Flask-Spectree
A thin Flask wrapper around spectree that adds useful CLI tools for exporting and flattening OpenAPI specs while not affecting any other aspect of Spectree's normal usage patterns.
Installation
pip install flask-spectree
Requires Flask >= 3.0 and spectree >= 1.3.
Usage
Direct initialization
from flask import Flask
from flask_spectree import FlaskSpecTree
app = Flask(__name__)
spec = FlaskSpecTree(app)
App-factory pattern
from flask_spectree import FlaskSpecTree
spec = FlaskSpecTree()
def create_app():
app = Flask(__name__)
spec.init_app(app)
return app
After registration, the OpenAPI spec is served at /apidoc/openapi.json.
Configuration
| Config key | Description |
|---|---|
SPECTREE_TITLE |
Title shown in the spec |
All other spectree options can be passed as keyword arguments to FlaskSpecTree(...).
CLI
After registering the extension, a spec command group is added to the Flask CLI.
Export the spec
flask spec export [OPTIONS]
| Option | Default | Description |
|---|---|---|
--format [json|ts|raw] |
json |
Output format |
--flat |
off | Flatten schema before output (reduces nested duplication) |
-o / --output-file |
stdout | Write output to a file |
Examples:
# Print JSON to stdout
flask spec export
# Write flattened JSON to a file
flask spec export --flat -o openapi.json
# Generate TypeScript types (requires `npx openapi-typescript`)
flask spec export --format ts -o src/api.d.ts
Flatten a spec file
Promotes nested Pydantic v2 component schemas to root level, strips hash suffixes, and deduplicates identical schemas.
flask spec flatten [OPTIONS]
| Option | Default | Description |
|---|---|---|
-i / --input-file |
stdin | Input OpenAPI JSON file |
-o / --output-file |
stdout | Output file |
Examples:
# Flatten from file to file
flask spec flatten -i openapi.json -o openapi.flat.json
# Pipe
cat openapi.json | flask spec flatten > openapi.flat.json
Schema flattening
Pydantic v2 generates verbose schema names like AccessoryDetailOut.90e892a and AccessoryDetailOut.90e892a.UserNested. The flattener:
- Strips hash suffixes (
AccessoryDetailOut.90e892a→AccessoryDetailOut) - Promotes child schemas (
Parent.hash.Child→Child) - Deduplicates identical schemas across two passes
- Disambiguates genuinely different schemas with
Parent_Childnaming - Rewrites all
$refvalues throughout the document
Metadata
Release files for Flask-Spectree 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_spectree-1.1.1.tar.gz | 54.6 kB | Without provenance | Details for flask_spectree-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_spectree-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for flask_spectree-1.1.1-py3-none-any.whl |
Total release size: 63.3 kB
Release files / flask_spectree-1.1.1.tar.gz
| Download URL | flask_spectree-1.1.1.tar.gz |
|---|---|
| Size | 54.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a7688bc89dbb80b1f41a58c0d5076f0665092327abddfc9c4718d7c37f24b6d
|
|
BLAKE2b-256 checksum How to use checksums |
d41f20e262e1c0d6f444fc79838941a0a0ae5adcadfc3c3637aa39af55e893b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / flask_spectree-1.1.1-py3-none-any.whl
| Download URL | flask_spectree-1.1.1-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b59d9ca4abec0e3d72283509953654de0479dfdd9150ae2e04a5ad4f90e88375
|
|
BLAKE2b-256 checksum How to use checksums |
2092d577757fdd3d68b03f8867bbdef6c425f5c55dbe70b428a64a2a9ebcdba6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for Flask-Spectree 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.