{"id":27431,"library":"surrogate","title":"surrogate","description":"A Python micro-library to create stubs for non-existing modules, enabling testing of import-dependent code. Current version 0.1, no active development observed.","status":"active","version":"0.1","language":"python","source_language":"en","source_url":"https://github.com/JASchilz/surrogate","tags":["testing","stubs","mock","import"],"install":[{"cmd":"pip install surrogate","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"surrogate","correct":"import surrogate"}],"quickstart":{"code":"import surrogate\n\n# Create a stub for a non-existing module\nsurrogate.replace('mymodule')\n\n# Now you can import it without ImportError\nimport mymodule\n\n# Check that it's indeed a stub\nprint(isinstance(mymodule, surrogate.Surrogate))\n\n# Automatic cleanup on exit","lang":"python","description":"Creates stubs for modules that don't exist, allowing import without error."},"warnings":[{"fix":"Call surrogate.replace('module_name') before any import of that module.","message":"surrogate.replace() must be called before importing the target module, otherwise the real module will be cached.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need attributes, assign them manually after creating the stub.","message":"Stubs are not full mocks; they only prevent ImportError. Attributes accessed on the stub will raise AttributeError unless defined.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.1':24 'activ':26 'code':21 'creat':8 'current':22 'depend':20 'develop':27 'enabl':15 'exist':13 'import':19,32 'import-depend':18 'librari':6 'micro':5 'micro-librari':4 'mock':31 'modul':14 'non':12 'non-exist':11 'observ':28 'python':3 'stub':9,30 'surrog':1 'test':16,29 'version':23","created_at":"2026-05-01T17:46:14.174814+00:00","updated_at":"2026-05-01T17:46:14.174814+00:00","problems":[{"fix":"Ensure you are using version 0.1 and call surrogate.replace().","cause":"Using an older version of surrogate where the function was named differently.","error":"AttributeError: module 'surrogate' has no attribute 'replace'"},{"fix":"Ensure surrogate.replace() is called before any imports of the module.","cause":"The module was already imported before calling surrogate.replace().","error":"ImportError after surrogate.replace()"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/JASchilz/surrogate","docs":null,"changelog":null,"pypi":"https://pypi.org/project/surrogate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}