CLI Reference
The tywrap CLI has two commands: init and generate.
Installation
npm install tywrapOr run it with npx:
npx tywrap <command>tywrap init
Creates a starter config file in the current directory.
- The default file is
tywrap.config.ts. - If you do not pass
--modules, the starter config wrapsmath. - If a
package.jsonis present, tywrap addstywrap:generateandtywrap:checkscripts unless you pass--no-scripts.
npx tywrap init
npx tywrap init --format json --modules math,numpy| Flag | Description |
|---|---|
--config, -c | Path for the new config file |
--format ts|json | Output format for the starter config |
--modules | Comma-separated Python modules to seed into the config |
--runtime node|pyodide|http|auto | Accepted for compatibility. Set the active runtime under top-level runtime in the generated config. |
--output-dir | Generated wrapper directory in the starter config |
--force | Overwrite an existing config file |
--scripts, --no-scripts | Add or skip recommended package.json scripts |
tywrap generate
Reads config and writes generated wrapper files from Python IR.
When --config is omitted, the CLI searches in this order:
tywrap.config.tstywrap.config.mtstywrap.config.jstywrap.config.mjstywrap.config.cjstywrap.config.json
If no config file is found, you can still generate wrappers by passing --modules.
npx tywrap generate
npx tywrap generate --config ./tywrap.config.json
npx tywrap generate --modules math,statistics --runtime node| Flag | Description |
|---|---|
--config, -c | Config file path |
--modules | Comma-separated Python modules to wrap |
--runtime node|pyodide|http|auto | Accepted for compatibility. Set the active runtime under top-level runtime in the config. |
--python | Python executable path override |
--output-dir | Override output.dir |
--format esm|cjs|both | Override output.format |
--declaration | Override output.declaration and emit matching .d.ts files |
--source-map | Override output.sourceMap |
--cache, --no-cache | Enable or disable on-disk IR caching |
--debug | Enable debug logging |
--verbose, -v | Alias for --debug |
--fail-on-warn | Exit non-zero when generation emits warnings |
--check | Compare generated output with what is on disk without writing files |
tywrap generate --check
--check is for CI and upgrade verification. It does not write files.
A normal generation writes <module>.contract.json beside the generated wrapper. Check mode compares against it without writing. The contract is byte-stable across machines and Python processes. --check compares that file as well as generated TypeScript, declaration files, and source maps when those outputs are enabled, so it also reports contract drift.
Set contractInput in the config to regenerate from a pinned contract without starting Python. The TypeScript generator and the Python extractor use IR version 0.4.0. Generation fails with a version-mismatch error that names the expected and received versions when they differ.
npx tywrap generate --checkExit codes:
0: generated files are up to date2: generation succeeded but warnings were present and--fail-on-warnwas set3: generated files are out of date1: general failure, including missing config or import failure
Typical CI step:
- name: Check generated wrappers
run: npx tywrap generate --checkStarter Config Example
import { defineConfig } from 'tywrap';
export default defineConfig({
pythonModules: {
math: { typeHints: 'strict' },
numpy: { typeHints: 'strict', alias: 'np' },
},
output: {
dir: './generated',
format: 'esm',
declaration: false,
sourceMap: false,
},
runtime: {
node: {
pythonPath: 'python3',
},
},
types: {
presets: ['stdlib'],
},
});See the Configuration guide for the full config surface.