synapse
AST-driven dependency tracer and token calculator for AI-assisted coding workflows.
Instead of dumping entire folders into an LLM's context window, synapse walks
your Python codebase's import graph (including src/ layouts, relative imports,
__init__.py re-exports, and namespace packages) and extracts only the files —
or referenced symbols — transitively relevant to your target file, with token
counts so you know exactly what you're spending.
Install
pip install synapse-ast
For local development with tests:
pip install -e ".[dev]"
pytest
Usage
synapse --version
synapse map . # scan a repo, print structural summary
synapse map . --json # machine-readable JSON summary
synapse pack path/to/file.py # pack dependency chain to stdout
synapse pack file.py --depth 3 --budget 8000 # limit depth and warn if over token budget
synapse pack file.py --symbols # slice dependencies to referenced defs/classes
synapse pack file.py --format markdown # text | markdown | xml | json
synapse pack file.py --exclude-type-checking # skip `if TYPE_CHECKING:` imports
synapse pack file.py --output clipboard # copy to clipboard (or --output file --out-file out.txt)
Key options
--root <path>: repository root (defaults to.).--depth, -d <int>: maximum traversal depth for local dependencies (default2).--budget, -b <int>: token budget; prints a warning tostderrif stripped tokens exceed budget.--symbols / --full-files: slice dependency files (depth >= 1) to only referenced functions, classes, constants, and imports while keeping the target intact (default:--full-files).--format, -f <fmt>: output format (text,markdown,xml,json; defaulttext).--output, -o <dest>: destination (stdout,clipboard,file; defaultstdout) with--out-file.--strip-comments / --keep-comments,--strip-docstrings / --keep-docstrings,--strip-blank / --keep-blank.--include-type-checking / --exclude-type-checking: include or excludeif TYPE_CHECKING:blocks (default: include).--no-cache: ignore and bypass.synapse/cache.jsonfor a full re-parse.
Design notes
- Clean
stdout/stderrsplit onpack: only packed code goes tostdoutsosynapse pack file.py > context.txtstays clean; cache stats, token tables, and warnings go tostderr. - Offline
tiktokenfallback:cl100k_baseis used when available; iftiktokencannot download its BPE table (e.g. offline/corporate proxy),synapsedegrades gracefully to an approximate~4 chars/tokenestimate and labels the output as approximate onstderr. - Caching (
.synapse/): parsed AST symbol maps are cached in.synapse/cache.jsonusing mtime + SHA-256 invalidation, and.synapse/is automatically added to.gitignoreon first cached run.
Metadata
Release files for synapse-ast 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| synapse_ast-0.1.0.tar.gz | 35.5 kB | Without provenance | Details for synapse_ast-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| synapse_ast-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for synapse_ast-0.1.0-py3-none-any.whl |
Total release size: 66.9 kB
Release files / synapse_ast-0.1.0.tar.gz
| Download URL | synapse_ast-0.1.0.tar.gz |
|---|---|
| Size | 35.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb7380fde7fca0a82d9e3815b70f592ff5ea4892937aa5d8375d7e85d99bab05
|
|
BLAKE2b-256 checksum How to use checksums |
1ed0666ec1ddb53e6cd0b3ed5bd973f7abf835a0e2b382b92ebf4966583d6c76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / synapse_ast-0.1.0-py3-none-any.whl
| Download URL | synapse_ast-0.1.0-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fe3266a21d6f69b8e69448bd9e918b0afba3f25bb6693ea1fe95ccfe21e81da
|
|
BLAKE2b-256 checksum How to use checksums |
8d0621bd0e2f1cfb0a515ac321a1a49c6e40d42490ba79fe76298b54c03415a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for synapse-ast 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.