{"id":50450349,"url":"https://github.com/JelleZijlstra/pycroscope","last_synced_at":"2026-06-17T16:01:34.021Z","repository":{"id":291354650,"uuid":"977377657","full_name":"JelleZijlstra/pycroscope","owner":"JelleZijlstra","description":"A Python type checker","archived":false,"fork":false,"pushed_at":"2026-06-02T04:59:32.000Z","size":6828,"stargazers_count":39,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-02T06:05:59.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JelleZijlstra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-05-04T04:11:20.000Z","updated_at":"2026-06-02T04:59:34.000Z","dependencies_parsed_at":"2026-06-02T06:03:26.763Z","dependency_job_id":null,"html_url":"https://github.com/JelleZijlstra/pycroscope","commit_stats":null,"previous_names":["jellezijlstra/pycroscope"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/JelleZijlstra/pycroscope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelleZijlstra%2Fpycroscope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelleZijlstra%2Fpycroscope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelleZijlstra%2Fpycroscope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelleZijlstra%2Fpycroscope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JelleZijlstra","download_url":"https://codeload.github.com/JelleZijlstra/pycroscope/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JelleZijlstra%2Fpycroscope/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34453446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-01T00:00:38.859Z","updated_at":"2026-06-17T16:01:34.015Z","avatar_url":"https://github.com/JelleZijlstra.png","language":"Python","funding_links":[],"categories":["Static type checkers"],"sub_categories":[],"readme":"# pycroscope\n\nPycroscope is a semi-static type checker for Python code. Like a static type checker (e.g., mypy or pyright), it\ndetects type errors in your code so bugs can be found before they reach production. Unlike such tools, however,\nit imports the modules it type checks, enabling pycroscope to understand many dynamic constructs that other type\ncheckers will reject. This property also makes it possible to extend pycroscope with plugins that interact directly\nwith your code.\n\nPycroscope is a friendly fork of [pyanalyze](https://github.com/quora/pyanalyze).\n\n## Usage\n\nYou can install pycroscope with:\n\n```bash\n$ pip install pycroscope\n```\n\nOnce it is installed, you can run pycroscope on a Python file or package as follows:\n\n```bash\n$ python -m pycroscope file.py\n$ python -m pycroscope package/\n```\n\nBut note that this will try to import all Python files it is passed. If you have scripts that perform operations without `if __name__ == \"__main__\":` blocks, pycroscope may end up executing them.\n\nIn order to run successfully, pycroscope needs to be able to import the code it checks. To make this work you may have to manually adjust Python's import path using the `$PYTHONPATH` environment variable.\n\nFor quick experimentation, you can also use the `-c` option to directly type check a piece of code:\n\n```\n$ python -m pycroscope -c 'import typing; typing.reveal_type(1)'\nRuntime type is 'int'\n\nRevealed type is 'Literal[1]' (code: reveal_type)\nIn \u003ccode\u003e at line 1\n   1: import typing; typing.reveal_type(1)\n                                        ^\n```\n\nPycroscope tries to minimize its dependencies, and some functionality is available only if certain\ndependencies are installed. You can install all optional dependencies with\n`pip install pycroscope[full]`. This will install:\n\n- `asynq` and `qcore`, used for type checking code using the `asynq` framework\n- `codemod`, used for interactive autofixing of some errors\n- `ast_decompiler`, used to create higher-quality autofixes\n\n### Configuration\n\nPycroscope has a number of command-line options, which you can see by running `python -m pycroscope --help`. Important ones include `-f`, which runs an interactive prompt that lets you examine and fix each error found by pycroscope, and `--enable`/`--disable`, which enable and disable specific error codes.\n\nConfiguration through a `pyproject.toml` file is also supported. See\n[the documentation](https://pycroscope.readthedocs.io/en/latest/configuration.html) for\ndetails.\n\n### Extending pycroscope\n\nOne of the main ways to extend pycroscope is by providing a specification for a particular function. This allows you to run arbitrary code that inspects the arguments to the function and raises errors if something is wrong.\n\nAs an example, suppose your codebase contains a function `database.run_query()` that takes as an argument a SQL string, like this:\n\n```python\ndatabase.run_query(\"SELECT answer, question FROM content\")\n```\n\nYou want to detect when a call to `run_query()` contains syntactically invalid SQL or refers to a non-existent table or column. You could set that up with code like this:\n\n```python\nfrom pycroscope.error_code import ErrorCode\nfrom pycroscope.signature import CallContext, Signature, SigParameter\nfrom pycroscope.value import KnownValue, TypedValue, AnyValue, AnySource, Value\n\nfrom database import run_query, parse_sql\n\n\ndef run_query_impl(ctx: CallContext) -\u003e Value:\n    sql = ctx.vars[\"sql\"]\n    if not isinstance(sql, KnownValue) or not isinstance(sql.val, str):\n        ctx.show_error(\n            \"Argument to run_query() must be a string literal\",\n            ErrorCode.incompatible_call,\n        )\n        return AnyValue(AnySource.error)\n\n    try:\n        parsed = parse_sql(sql)\n    except ValueError as e:\n        ctx.show_error(\n            f\"Invalid sql passed to run_query(): {e}\",\n            ErrorCode.incompatible_call,\n        )\n        return AnyValue(AnySource.error)\n\n    # check that the parsed SQL is valid...\n\n    # pycroscope will use this as the inferred return type for the function\n    return TypedValue(list)\n\n\n# in pyproject.toml, set:\n# known_signatures = [\"\u003cmodule\u003e.get_known_argspecs\"]\ndef get_known_argspecs(arg_spec_cache):\n    return {\n        # This infers the parameter types and names from the function signature\n        run_query: arg_spec_cache.get_argspec(\n            run_query, impl=run_query_impl\n        ),\n        # You can also write the signature manually\n        run_query: Signature.make(\n            [SigParameter(\"sql\", annotation=TypedValue(str))],\n            callable=run_query,\n            impl=run_query_impl,\n        ),\n    }\n```\n\n### Supported features\n\nPycroscope generally aims to implement [the Python typing spec](https://typing.readthedocs.io/en/latest/spec/index.html),\nbut support for some features is incomplete. See [the documentation](https://pycroscope.readthedocs.io/en/latest/)\nfor details.\n\n### Ignoring errors\n\nSometimes pycroscope gets things wrong and you need to ignore an error it emits. This can be done as follows:\n\n- Add `# static analysis: ignore` on a line by itself before the line that generates the error.\n- Add `# static analysis: ignore` at the end of the line that generates the error.\n- Add `# static analysis: ignore` at the top of the file; this will ignore errors in the entire file.\n\nYou can add an error code, like `# static analysis: ignore[undefined_name]`, to ignore only a specific error code. This does not work for whole-file ignores. If the `bare_ignore` error code is turned on, pycroscope will emit an error if you don't specify an error code on an ignore comment.\n\nPycroscope does not currently support the standard `# type: ignore` comment syntax.\n\n### Python version support\n\nPycroscope supports all versions of Python that have not reached end-of-life. Because it imports the code it checks, you have to run it using the same version of Python you use to run your code.\n\n## Contributing\n\nWe welcome your contributions. See [CONTRIBUTING.md](https://github.com/JelleZijlstra/pycroscope/blob/master/CONTRIBUTING.md)\nfor how to get started.\n\n## Documentation\n\nDocumentation is available on [GitHub](https://github.com/JelleZijlstra/pycroscope/tree/master/docs).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJelleZijlstra%2Fpycroscope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJelleZijlstra%2Fpycroscope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJelleZijlstra%2Fpycroscope/lists"}