Skip to main content

Automatic RESTful API generator with redoc

Project description

flarchitect

Docs Tests Coverage PyPI version

flarchitect is a friendly Flask extension that turns your SQLAlchemy or Flask-SQLAlchemy models into a production-ready REST API in minutes while keeping you in full control of your models and endpoints. It automatically builds CRUD endpoints, generates interactive Redoc documentation and keeps responses consistent so you can focus on your application logic.

Why flarchitect?

If you're new here, welcome! flarchitect gets you from data models to a fully fledged REST API in minutes, saving you time without sacrificing quality or customisation.

Features

  • Automatic CRUD endpoints – expose SQLAlchemy models as RESTful resources with a simple Meta class.
  • Interactive documentation – Redoc or Swagger UI generated at runtime and kept in sync with your models.
  • Built-in authentication – JWT, basic and API key strategies ship with a ready‑made /auth/login endpoint, or plug in your own.
  • Extensibility hooks – customise request and response flows.
  • Soft delete – hide and restore records without permanently removing them.
  • GraphQL integration – expose your models through a single /graphql endpoint when you need more flexible queries.

Optional extras

  • Rate limiting & structured responses – configurable throttling and consistent response schema.
  • Field validation – built-in validators for emails, URLs, IPs and more.
  • Nested writes – send related objects in POST/PUT payloads when API_ALLOW_NESTED_WRITES is True.
  • CORS support – enable cross-origin requests with API_ENABLE_CORS.

Installation

flarchitect supports Python 3.10 and newer. Set up a virtual environment, install the package and verify the install:

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install flarchitect
python -c "import flarchitect; print(flarchitect.__version__)"

The final command prints the version number to confirm everything installed correctly.

Quick Start

from flask import Flask
from flarchitect import Architect
from models import Author, BaseModel  # your SQLAlchemy models

app = Flask(__name__)
app.config["API_TITLE"] = "My API"
app.config["API_VERSION"] = "1.0"
app.config["API_BASE_MODEL"] = BaseModel
app.config["API_ALLOW_NESTED_WRITES"] = True

architect = Architect(app)

if __name__ == "__main__":
    app.run(debug=True)

With the application running, try your new API in another terminal window:

curl http://localhost:5000/api/authors

Authentication

flarchitect ships with ready-to-use JWT, Basic and API key authentication. Choose strategies with API_AUTHENTICATE_METHOD.

JWT

app.config["API_AUTHENTICATE_METHOD"] = ["jwt"]
app.config["ACCESS_SECRET_KEY"] = "access-secret"
app.config["REFRESH_SECRET_KEY"] = "refresh-secret"
app.config["API_USER_MODEL"] = User
app.config["API_USER_LOOKUP_FIELD"] = "username"
app.config["API_CREDENTIAL_CHECK_METHOD"] = "check_password"

Basic

app.config["API_AUTHENTICATE_METHOD"] = ["basic"]
app.config["API_USER_MODEL"] = User
app.config["API_USER_LOOKUP_FIELD"] = "username"
app.config["API_CREDENTIAL_CHECK_METHOD"] = "check_password"

API key

app.config["API_AUTHENTICATE_METHOD"] = ["api_key"]
app.config["API_KEY_AUTH_AND_RETURN_METHOD"] = lookup_user_by_token
# app.config["API_CREDENTIAL_HASH_FIELD"] = "api_key_hash"  # optional

See the authentication docs for full configuration details and custom strategies.

OpenAPI specification

An OpenAPI 3 schema is generated automatically and powers the Redoc UI. You can switch to Swagger‑UI by setting API_DOCS_STYLE = 'swagger' in your Flask config. Either way you can serve the raw specification to integrate with tooling such as Postman:

from flask import Flask
from flarchitect import Architect

app = Flask(__name__)
architect = Architect(app)  # OpenAPI served at /openapi.json, docs served at /docs

The specification endpoint can be customised with API_SPEC_ROUTE. See the OpenAPI docs for exporting or customising the document.

GraphQL

Prefer working with a single endpoint? flarchitect can turn your SQLAlchemy models into a GraphQL schema with just a couple of lines. Generate the schema and register it with the architect:

from flarchitect.graphql import create_schema_from_models

schema = create_schema_from_models([Item], db.session)
architect.init_graphql(schema=schema)

With the server running you can open GraphiQL at http://localhost:5000/graphql and explore your data interactively. Use the all_items query to fetch existing records:

query {
    all_items {
        id
        name
    }
}

The GraphQL demo contains ready-made models and sample queries to help you get started.

Read about hiding and restoring records in the soft delete section.

Running Tests

To run the test suite locally:

pip install -e .[dev]
export ACCESS_SECRET_KEY=access
export REFRESH_SECRET_KEY=refresh
pytest

The ACCESS_SECRET_KEY and REFRESH_SECRET_KEY environment variables are required for JWT-related tests. Adjust the export commands for your shell and operating system.

Documentation & help

Roadmap

Check out the project roadmap for upcoming features and enhancements.

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

Before submitting a pull request, ensure that development dependencies are installed and linters and tests pass locally:

pip install -e .[dev]
ruff --fix .
export ACCESS_SECRET_KEY=access
export REFRESH_SECRET_KEY=refresh
pytest

Versioning & Releases

The package version is defined in pyproject.toml and exposed as flarchitect.__version__. A GitHub Actions workflow automatically publishes to PyPI when the version changes on master.

To publish a new release:

  1. Update the version field in pyproject.toml (for example with hatch version patch).
  2. Commit and push to master.

Ensure the repository has a PYPI_API_TOKEN secret with an API token from PyPI.

License

Distributed under the MIT License. See LICENSE for details.

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

flarchitect-0.1.2.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flarchitect-0.1.2-py3-none-any.whl (108.9 kB view details)

Uploaded Python 3

File details

Details for the file flarchitect-0.1.2.tar.gz.

File metadata

  • Download URL: flarchitect-0.1.2.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flarchitect-0.1.2.tar.gz
Algorithm Hash digest
SHA256 960d79628564fb17b2b6d8ac30f9ce81dd9c0951290937b7a7a56c4481e5a388
MD5 5d9871fabbd0a4baa0550b22dbaae272
BLAKE2b-256 0fd4107f6a8ff2e71c9591d4036c59f55ef2e0e3caa4b6eb055015715a472bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for flarchitect-0.1.2.tar.gz:

Publisher: release.yml on lewis-morris/flarchitect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flarchitect-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: flarchitect-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 108.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flarchitect-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95adc810bd24679b34ccd45d0add9e1c8e2ed550965b11857601d5e50f07aeb3
MD5 d148e53ab825a4b18c695baa5b437f9f
BLAKE2b-256 404b05068ffc81810720db0b97e83e71c9667b5aa4fd0e035b23518f137d1bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for flarchitect-0.1.2-py3-none-any.whl:

Publisher: release.yml on lewis-morris/flarchitect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page