Auto-generate TypeScript client code from Flask routes and Python type annotations.
Project description
Typesync
This project aims to automatically generate TypeScript types and client-side request helpers directly from a Flask application. It is heavily inspired by JS Flask URLs.
By inspecting Flask routes and their Python type annotations, it produces strongly typed TypeScript definitions and functions that can call those endpoints with correct argument and return types. The project is currently incomplete, but the core idea and basic functionality are already in place.
The main goal is to reduce duplication and type mismatches between backend and frontend codebases by treating the Flask app as the single source of truth for API structure and typing.
Intended and Existing Features
Some features are already implemented, others are planned.
- Parse Flask routes and URL rules
- Parse route argument types from annotations
- Parse return types from annotated view functions
- Generate TypeScript type definitions
- Generate TypeScript request/helper functions for endpoints
- CLI integration with Flask via a custom command
- Vite support
- Handling of Flask converters (custom and built-in)
- Support for multiple HTTP methods (GET, POST, PUT, DELETE, etc.)
- Support for JSON request bodies with typed parameters
- Support validators such as pydantic
- Support for
typing.Annotatedto:- Ignore specific routes
- Customize generation behavior (naming, visibility, etc.)
- Improved error reporting for unsupported or ambiguous annotations
- Optional generation modes (types only, requests only)
- Configuration file support
- Support custom formatting for generated code
- Handle recursive types (such as
type RecursiveType = tuple[int, RecursiveType])* - Support returning with
jsonify(...) - Support extensions via translators
* Not all cases are supported.
Installation
You can install typesync using pip install typesync. Alternatively, you can do it directly from source, preferably using uv, by cloning the repository and installing dependencies:
git clone https://github.com/ArmindoFlores/typesync
cd typesync
uv sync --dev
uv pip install -e .
Usage
TypeScript generation
The tool is exposed as a Flask CLI command. Inside your Flask application environment, run:
flask typesync generate OUT_DIR
This command will load the Flask app, inspect the URL map and registered view functions, and generate the corresponding TypeScript files (types and request helpers), placing them inside OUT_DIR. The names of the generated files, types, and functions can be customized using command line options. For more information about these options, use flask typesync generate --help.
Using the generated code
The main output of typesync is a makeAPI() function that is used to instantiate an object containing a function per HTTP method per endpoint. An example on how to use this function is provided in example/frontend/src/api.ts.
Rollup Plugin
Typesync has a rollup plugin that can be used to integrate with Rollup/Vite projects. Additional documentation is provided in rollup-plugin-typesync/README.md.
Inference
Typesync is capable of some basic type inference. This can be helpful when trying to incrementally adopt this package in an existing codebase, or for unconventional Flask setups. This functionality is optional, and needs to be enabled using the --inference flag. Additionally, the inference module may need to use eval() for evaluating some types; this is disabled by default, but can be enabled using --inference-can-eval.
Running Tests
Tests can be run using pytest:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typesync-0.0.1a4.tar.gz.
File metadata
- Download URL: typesync-0.0.1a4.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1be3be6cdedb9e258dcbf783b9e00aeaafe904832aa88b5f6193bf44f25c26d5
|
|
| MD5 |
941372e0f467ec0a3d4d81ad54d1670d
|
|
| BLAKE2b-256 |
4d59208bd8576bb24eaa319bbd9159c29eaf8180290ac2305c2a4fce63e1df68
|
Provenance
The following attestation bundles were made for typesync-0.0.1a4.tar.gz:
Publisher:
release.yml on ArmindoFlores/typesync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typesync-0.0.1a4.tar.gz -
Subject digest:
1be3be6cdedb9e258dcbf783b9e00aeaafe904832aa88b5f6193bf44f25c26d5 - Sigstore transparency entry: 945923692
- Sigstore integration time:
-
Permalink:
ArmindoFlores/typesync@2d153a23416d9b3f421e67abbf14b425748e217d -
Branch / Tag:
refs/tags/v0.0.1-a4 - Owner: https://github.com/ArmindoFlores
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2d153a23416d9b3f421e67abbf14b425748e217d -
Trigger Event:
release
-
Statement type:
File details
Details for the file typesync-0.0.1a4-py3-none-any.whl.
File metadata
- Download URL: typesync-0.0.1a4-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98870daa0d02dc4d8eb56a3e9ee75610eeecac7e20fd6e2f4679997d7aa68bdd
|
|
| MD5 |
89448bb48bf7be5730333d2b039d03de
|
|
| BLAKE2b-256 |
7ce04d1f461c77e5bccd9ec05ce0f9e31bd0542b0216d433bb495c9659d75aa5
|
Provenance
The following attestation bundles were made for typesync-0.0.1a4-py3-none-any.whl:
Publisher:
release.yml on ArmindoFlores/typesync
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typesync-0.0.1a4-py3-none-any.whl -
Subject digest:
98870daa0d02dc4d8eb56a3e9ee75610eeecac7e20fd6e2f4679997d7aa68bdd - Sigstore transparency entry: 945923721
- Sigstore integration time:
-
Permalink:
ArmindoFlores/typesync@2d153a23416d9b3f421e67abbf14b425748e217d -
Branch / Tag:
refs/tags/v0.0.1-a4 - Owner: https://github.com/ArmindoFlores
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2d153a23416d9b3f421e67abbf14b425748e217d -
Trigger Event:
release
-
Statement type: