Generate TypeScript clients from Django APIs
Project description
Django TypeScript API Generator
A zero-dependency Django plugin that automatically generates TypeScript interfaces and documentation from your Django models.
Features
- Zero Dependencies: Uses only Django and Python standard libraries
- Type-Safe Interfaces: Generate TypeScript interfaces from Django models
- Comprehensive Documentation: Automatic JSDoc generation with field descriptions and validation rules
- Validation Constraints: Extracts min/max length, value constraints, regex patterns, and choices
- Highly Configurable: Customize through Django settings or command-line options
- Scalable Architecture: Built with design patterns for future extensibility
Installation
Add to your INSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
# ...
'django_typescript_api',
]
Configure (optional):
# settings.py
DJANGO_TYPESCRIPT_API = {
'OUTPUT_PATH': 'frontend/src/api/generated.ts',
'INCLUDE_DOCS': True,
'INCLUDE_VALIDATORS': True,
'TYPE_MAPPINGS': {
'DecimalField': 'string', # Override default mapping
}
}
Usage
# Generate TypeScript interfaces
python manage.py generate_ts_client
# Specific output file
python manage.py generate_ts_client --output frontend/src/api/models.ts
# Only specific apps
python manage.py generate_ts_client --apps blog users
# Skip documentation
python manage.py generate_ts_client --no-docs
# Skip validation constraints
python manage.py generate_ts_client --no-validators
# Verbose output with details
python manage.py generate_ts_client --verbose
# Dry run (preview without writing)
python manage.py generate_ts_client --dry-run
Example Output
// Generated by django-typescript-api
// DO NOT EDIT THIS FILE DIRECTLY
/**
* Blog post
* @interface Post
*/
export interface Post {
/**
* Post title
* @minLength 5
* @maxLength 200
*/
title: string;
/**
* Publication status
* @enum {'draft', 'published', 'archived'}
*/
status: 'draft' | 'published' | 'archived';
/**
* When the post was created
*/
created_at: string;
}
export interface User {
// ... with similar documentation
}
Supported Field Types
- String fields:
CharField,TextField,EmailField,SlugField, etc. - Numeric fields:
IntegerField,FloatField,DecimalField, etc. - Boolean fields:
BooleanField - Date/time fields:
DateField,DateTimeField,TimeField - Relations:
ForeignKey,OneToOneField,ManyToManyField - Special fields:
UUIDField,JSONField,FileField
Configuration Options
| Setting | Default | Description |
|---|---|---|
| OUTPUT_PATH | frontend/src/api/generated.ts | Output file path |
| INCLUDE_DOCS | True | Generate JSDoc documentation |
| INCLUDE_VALIDATORS | True | Include validation constraints |
| TYPE_MAPPINGS | {} | Custom Django-to-TypeScript type mappings |
| CUSTOM_HEADERS | Predefined | Custom file header comments |
Roadmap
- Phase 2: API endpoint generation from DRF viewsets
- Phase 3: Query parameter typing and advanced features
- Phase 4: Performance optimizations and extensibility hooks
Contributing
This is currently in active development. The architecture is designed with scalability in mind using Builder, Visitor, and Strategy patterns.
License
MIT License – feel free to use and contribute!
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 django_typescript_api-0.1.0rc1.tar.gz.
File metadata
- Download URL: django_typescript_api-0.1.0rc1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45d5df7204075fc105a32e83d0e94635c92cb8bbf085c5bc9bba1efb7bd7c6ae
|
|
| MD5 |
0e496365d7efc7bb0bc78bd2d0100a76
|
|
| BLAKE2b-256 |
d3e1ab0fbcc9758147c6de36d120dd2703e57ea4a15ca4df6f73abf4d24bc532
|
Provenance
The following attestation bundles were made for django_typescript_api-0.1.0rc1.tar.gz:
Publisher:
pypi_publish.yml on pyenvstudio/django-typescript-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_typescript_api-0.1.0rc1.tar.gz -
Subject digest:
45d5df7204075fc105a32e83d0e94635c92cb8bbf085c5bc9bba1efb7bd7c6ae - Sigstore transparency entry: 495004760
- Sigstore integration time:
-
Permalink:
pyenvstudio/django-typescript-api@62ecfc670789c493ad86734b16fe370efe9d4322 -
Branch / Tag:
refs/tags/v0.1.0rc1 - Owner: https://github.com/pyenvstudio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@62ecfc670789c493ad86734b16fe370efe9d4322 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_typescript_api-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: django_typescript_api-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 14.3 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 |
45908eda9cf143f8fb7a1adf5d892f418c053928b515748253b1fc3b5a8b0e1d
|
|
| MD5 |
994a75cbca5ac7c903d5ba5ff54683f4
|
|
| BLAKE2b-256 |
9677696aa0ad7339610ee451b682f163496ba94cd14862bc75a281a215649b90
|
Provenance
The following attestation bundles were made for django_typescript_api-0.1.0rc1-py3-none-any.whl:
Publisher:
pypi_publish.yml on pyenvstudio/django-typescript-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_typescript_api-0.1.0rc1-py3-none-any.whl -
Subject digest:
45908eda9cf143f8fb7a1adf5d892f418c053928b515748253b1fc3b5a8b0e1d - Sigstore transparency entry: 495004795
- Sigstore integration time:
-
Permalink:
pyenvstudio/django-typescript-api@62ecfc670789c493ad86734b16fe370efe9d4322 -
Branch / Tag:
refs/tags/v0.1.0rc1 - Owner: https://github.com/pyenvstudio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@62ecfc670789c493ad86734b16fe370efe9d4322 -
Trigger Event:
release
-
Statement type: