This file helps AI coding assistants (Cursor, Copilot, Claude Code, Devin, Jules, Aider, Warp) understand the tywrap codebase and contribute effectively.
tywrap generates type-safe TypeScript wrappers for Python libraries. It has two components:
tywrap(npm) provides TypeScript/Node.js/Bun/Deno runtime bridges and a CLI code generatortywrap-ir(PyPI) provides a Python AST analyzer that extracts typed IR from Python source
The generated wrappers let you call Python functions from TypeScript with full type safety, using either a subprocess bridge (Node/Bun/Deno), in-browser WebAssembly (Pyodide), or HTTP.
# Setup
npm ci # Install Node.js dependencies
pip install -e tywrap_ir/ # Install Python component (editable)
# Build & type-check
npm run build # Compile TypeScript → dist/
npm run typecheck # tsc --noEmit (no output)
npm run lint # ESLint on src/ and test/
# Test
npm test # Full Vitest suite
npm run test:types # TSD type-level tests (test-d/)
npm run test:bun # Bun-specific tests (requires Bun installed)
npm run test:coverage # Coverage report → coverage/lcov.info
# Python integration tests
npm run test:python:suite:core # Core Python libs (stdlib, etc.)
npm run test:python:suite:data # Data libs (numpy, pandas, pyarrow)src/
index.ts # Public API re-exports
tywrap.ts # tywrap() factory and generate()
cli.ts # CLI entry point (tywrap init / generate)
dev.ts # Development helpers
config/ # Config loading and validation
core/ # Code generation pipeline
annotation-parser.ts # Type annotation parser
emit-call.ts # Wrapper call emission
generator.ts # TypeScript wrapper generator
mapper.ts # Python → TypeScript type mapper
runtime/ # Runtime bridges (see test/runtime_*.test.ts)
base-bridge.ts # Shared bridge lifecycle
bounded-context.ts # Disposable bounded-context base
bridge-codec.ts # Arrow/JSON codec with size limits
disposable.ts # Disposable primitives
frame-codec.ts # Transport frame encoding
http-transport.ts # HTTP transport implementation
index.ts # Runtime subpath exports
node.ts # NodeBridge — subprocess (Node, Bun, Deno)
pyodide.ts # PyodideBridge — browser WebAssembly
http.ts # HttpBridge — remote Python server
errors.ts # BridgeError, BridgeTimeoutError, etc.
pooled-transport.ts # Multi-process transport adapter
pyodide-bootstrap-core.generated.ts # Generated Pyodide bridge core
pyodide-transport.ts # Pyodide transport implementation
rpc-client.ts # Bridge RPC client
subprocess-transport.ts # Subprocess transport implementation
timed-out-request-tracker.ts # Late-response tracker
transport-pool.ts # Transport worker pool
transport.ts # Transport abstraction layer
validators.ts # Runtime payload validation
types/ # TypeScript type definitions
utils/ # Shared utilities
codec.ts # Arrow/JSON encode/decode
runtime.ts # detectRuntime(), isBun(), isDeno()
cache.ts # Artifact caching
ir-cache.ts # IR cache-key hashing
python.ts # Python path/env resolution
logger.ts # Structured logging
tywrap_ir/ # Python package: AST analysis → typed IR
tywrap_ir/
__main__.py # CLI entry: tywrap-ir
runtime/
python_bridge.py # Python subprocess server (JSONL protocol)
safe_codec.py # Python-side codec
test/ # Vitest tests mirroring src/ structure
test-d/ # TSD type tests
docs/ # Documentation (VitePress site)
examples/
living-app/ # End-to-end example with pandas + Arrow
generated/ # Generated wrapper output (gitignored in user projects)
dist/ # Compiled TypeScript output (do not edit)
- TypeScript strict mode; avoid
any; useunknownand type guards instead - Runtime bridges:
src/runtime/; corresponding tests:test/runtime_*.test.ts - Python code:
tywrap_ir/; follow PEP 8, use type hints - Generated files (
generated/,dist/): never edit manually TYWRAP_PERF_BUDGETS=1enables performance budget assertions in testsNODE_OPTIONS=--expose-gcrequired for GC-sensitive tests
Conventional commits with scope:
feat(runtime): add warmup supportfix(codec): handle oversized Arrow payloadstest(pyodide): add retry regressiondocs: update Bun runtime guidechore: bump vitest
- Include tests for new runtime behavior (see
test/runtime_*.test.tspatterns) - Run
npm run check:allbefore pushing; this runs format, lint, build, type tests, and unit tests - Wait for CI to be green including the
requiredjob - Resolve all CodeRabbit review threads before merging
| Var | Purpose |
|---|---|
TYWRAP_PERF_BUDGETS=1 |
Enable perf budget assertions |
NODE_OPTIONS=--expose-gc |
Enable GC for memory tests |
TYWRAP_CODEC_PYTHON=python |
Python path for codec tests |
TYWRAP_CODEC_MAX_BYTES |
Max response size (default 1MB) |
TYWRAP_CODEC_FALLBACK=json |
Disable Arrow, use JSON only |
TYWRAP_REQUEST_MAX_BYTES |
Max request payload size |