Skip to content

Folder Conversion

Convert all your Zod schemas at once. One command walks a folder, finds exported schemas, and writes a file per export.

Terminal window
schemabridge convert folder ./src/schemas --out ./generated --to pydantic

SchemaBridge scans every file in ./src/schemas, finds exported Zod schemas, and converts them to Python:

src/schemas/
├── user.ts → generated/user.py
├── product.ts → generated/product.py
└── common/
└── types.ts → generated/common/types.py

Your folder structure stays intact. Each exported schema becomes its own file (snake_case).

If one TypeScript file exports multiple schemas, each gets converted:

Input:

export const userSchema = z.object({ ... });
export const adminSchema = z.object({ ... });

Output:

generated/
├── user_schema.py
└── admin_schema.py

The file names come from the export names, converted to snake_case.

Want all files in one folder? Use --flat:

Terminal window
schemabridge convert folder ./src/schemas --out ./generated --flat
generated/
├── user.py
├── product.py
└── types.py

No subfolders, everything at the top level.

Add --init to create __init__.py files for proper Python imports:

Terminal window
schemabridge convert folder ./src/schemas --out ./generated --init
generated/
├── __init__.py
├── user.py
└── common/
├── __init__.py
└── types.py

Each generated __init__.py imports every model in that folder and re-exports child packages, so the package tree works with plain Python imports. This behavior only applies when generating Pydantic outputs (--to pydantic or --to all); for TypeScript-only runs, --init / generateInitFiles is ignored.

Now you can import like this:

from generated.user import UserSchema
from generated.common.types import TypesSchema

Add folder conversion to your build process:

scripts/generate.ts
import { convertFolder } from 'schemabridge';
await convertFolder({
sourceDir: './src/schemas',
outDir: './python/models',
target: 'pydantic',
preserveStructure: true,
generateInitFiles: true,
});
{
"scripts": {
"generate": "tsx scripts/generate.ts"
}
}

Run npm run generate and your Python models update automatically.

  • Only exported Zod schemas in files under sourceDir. Non-exported schemas (e.g., const schema = z.object(...)) are ignored.
  • Referenced schemas are inlined inside their parents; separate files are only created for exports.
  • Enums (z.enum([...])) become Literal[...] in Python and union types in .d.ts.
  • Use direct helpers: z.date(), z.coerce.date(), z.string().uuid(), z.string().email().
  • Avoid deprecated patterns like z.string().datetime() unless you truly want string output; otherwise consider z.date()/z.coerce.date().