CLI Usage
Client generation is one management command, python manage.py gen. It reads a
generation.py file that sits next to manage.py, runs the pipeline (drf-spectacular,
tag slicing, then the pinned external generator for each language) and writes every client
straight into the path of its target. TypeScript REST targets use Orval with Fetch,
React Query v5, Zod, and MSW; how a TypeScript tree is made is on the
Overview.
gen
python manage.py genGroups come from your openapi_client config (see Group Configuration); targets
come from generation.py (see Code Generation).
| Flag | Description |
|---|---|
--config PATH | Path to generation.py (default ./generation.py) |
--ts, --py, --go, --rust, --swift | Generate only for that language |
--target, -t TYPE | Only targets of that type: admin, web, packages, sdk, parsers, extensions |
--groups NAME [NAME ...] | Only these groups |
--dry-run | Print what would be generated, write nothing |
--list-targets | Print the configured targets and exit |
--check | Write nothing, run no tool; fail when a client’s CFG contract differs from the installed django-cfg, or when the Django schema changed since the client was generated |
--check-stamp | Write nothing; fail when a generated client’s CFG contract differs from the installed django-cfg |
--verbose / --quiet | More or less output |
python manage.py gen # all targets
python manage.py gen --ts # TypeScript only
python manage.py gen --groups core shop # two groups
python manage.py gen --target web --ts # web targets, TypeScript only
python manage.py gen --dry-run # plan only
python manage.py gen --list-targets
python manage.py gen --check # CI: are the clients current?The command exits non-zero when a target fails, so it is safe in CI.
Minimal setup
# api/config.py
from django_cfg import DjangoConfig, OpenAPIClientConfig, OpenAPIGroupConfig
class CryptoConfig(DjangoConfig):
openapi_client: OpenAPIClientConfig = OpenAPIClientConfig(
enabled=True,
groups=[
OpenAPIGroupConfig(name="core", apps=["users", "accounts", "api_keys"], title="Core API"),
OpenAPIGroupConfig(name="trading", apps=["wallets", "orders", "transactions"], title="Trading API"),
],
)# generation.py (next to manage.py)
from pathlib import Path
from django_cfg.modules.django_generator import Config, OpenAPI, Target, Language, TargetType
FRONTEND = Path(__file__).parent.parent / "frontend"
config = Config(
openapi=OpenAPI(
targets=[
Target(
lang=Language.TYPESCRIPT,
type=TargetType.WEB,
path=FRONTEND / "src" / "api" / "generated",
groups=["core", "trading"],
),
],
),
)TypeScript output is shaped by the Target options and the pinned frontend toolchain. Authentication, refresh, errors and response validation belong to the runtime. SSE, WebSocket and NDJSON adapters are separate protocol code. See the parameter table.
External tools
The generators are external programs: pinned Orval (TypeScript, Node 22.18+),
openapi-python-client, ogen (Go), cargo-progenitor (Rust: cargo install cargo-progenitor --version 0.17.0 --locked) and
swift-openapi-generator (Swift). Install the Python side with pip install "django-cfg[gen]". A missing tool
fails the target that needs it.
Cache and parallelism
The OpenAPI document is rendered fresh on every run (a few seconds). A target whose slice, options, external tool
and django-cfg code are all unchanged is replayed from its snapshot under openapi/.cache/ without running the
tool; the run prints (cached) next to it. Editing django-cfg’s generator or upgrading a tool invalidates the
snapshot by itself. Targets run in parallel.
| Variable | Effect |
|---|---|
DJANGO_CFG_GEN_NO_CACHE=1 | Run every tool, ignore the snapshots |
DJANGO_CFG_GEN_PARALLELISM=N | Worker count (default min(8, cpu_count, target_count)) |
DJANGO_CFG_GEN_QUIET=1 | Silence per-target output |
DJANGO_CFG_GEN_SKIP_TYPECHECK=1 | Publish TypeScript trees without the tsc --noEmit gate. Only for a reason outside the tree (for example a fresh checkout without the runtime’s built types); each skipped target prints type-check skipped |
The type-check gate
A TypeScript tree replaces the old one only if tsc --noEmit passes on it, with your app’s
TypeScript and nearest tsconfig.json. A failing target keeps its previous tree, and gen
exits non-zero with up to 20 diagnostics. Generate with DJANGO_CFG_GEN_SKIP_TYPECHECK=1 to
inspect such a tree, then run your app’s own tsc --noEmit.
CI
- name: Generate API clients
run: python manage.py gen
- name: Fail if generated clients are stale
run: git diff --exit-code frontend/src/api/generatedpython manage.py gen --check (make gen-check) is a cheaper gate that runs no external tool. Every
target keeps the slice it was generated from as openapi.json; the check renders the schema, cuts each
slice again and compares, then checks the CFG stamp. It names the operations and schemas that moved.
It does not see a hand edit of generated files, which only make gen plus git diff --exit-code
catches. --check-stamp checks the stamp alone and needs no schema render.
Best practices
- Commit the generated code, so a review shows what an API change does to the clients.
- Use groups to keep each target’s OpenAPI slice small; groups are selection boundaries, not separate npm packages or independent authentication stores.
- Put output paths in named constants at the top of
generation.py. - Use
--dry-runor--list-targetsbefore the first run to check the paths.