Configuration

Intro

In flarchitect, configuration options are essential for customizing the API and its accompanying documentation. These settings can be provided through Flask config values or directly within SQLAlchemy model classes using Meta classes.

Beyond the basics, the extension supports hooks and advanced flags for post-serialization callbacks, rate limiting, field exclusion, blueprint naming, endpoint naming via API_ENDPOINT_NAMER, soft deletion, and per-method documentation summaries.

Flask config values offer a straightforward, standardized way to modify the extension’s behavior at a global or model level.

Config Hierarchy

To offer flexibility and control, flarchitect follows a hierarchy of configuration priorities:

  • Lowest Priority – Global Flask config options apply to all requests and are overridden by any more specific configuration.

  • Method-based – Method-specific options can override global settings for particular HTTP methods.

  • Model-basedSQLAlchemy model Meta attributes override both global and method-based configurations.

  • Highest Priority – Model-specific configurations suffixed with an HTTP method allow the most detailed customization per model and method.

Note

When applying config values:

  • Global Flask config values are prefixed with API_.

  • Global method-based Flask config values are prefixed with API_{method}_.

  • SQLAlchemy model config values omit the API_ prefix and are lowercase.

  • SQLAlchemy model method config values omit the API_ prefix, are lowercase, and are prefixed with the method.

Note

Each configuration value below is assigned a tag, which defines where the value can be used and its priority:

Pri 1. Model Method - View here

Pri 2. Model - View here

Pri 3. Global Method - View here

Pri 4. Global - View here

Config Value Structure

Every configuration value has a specific structure that defines where it can be used and how it should be written. These structures are indicated by the badges in the configuration tables next to each value.

Please note the badge for each configuration value, as it defines where the value can be used and how it should be written.

Global

Global configuration values are the lowest priority and apply to all requests unless overridden by a more specific configuration.

They are applied in the Flask config object and are prefixed with API_.

These settings are ideal for defining application-wide defaults such as API metadata, documentation behaviour, or pagination policies. Any option listed in the configuration table can be supplied here using its global API_ form (for example API_TITLE or API_PREFIX) and may accept strings, integers, booleans, lists, or dictionaries depending on the option.

Use this level when you need a single setting to apply consistently across all models and methods.

Example:

class Config:
    API_TITLE = "My API"           # text shown in documentation header
    API_PREFIX = "/v1"             # apply a versioned base route
    API_CREATE_DOCS = True          # generate ReDoc documentation

See the Global page for more information.

Global Method

Global configuration values can apply to specific HTTP methods: GET, POST, PUT, DELETE, or PATCH.

The method name should be added after the API_ prefix.

Use method-scoped options to change behaviour between reads and writes across the entire API, such as applying tighter rate limits to mutating requests or disabling a verb globally. Any global configuration key that supports method scoping can be used here by inserting the method name (e.g. API_GET_RATE_LIMIT), with value types mirroring their global counterparts.

Example:

class Config:
    API_GET_RATE_LIMIT = "100 per minute"  # throttle read requests
    API_POST_BLOCKED = True                 # disable POST across the API
    API_PATCH_RATE_LIMIT = "10 per minute"  # tighter limits on writes

See the Global Method page for more information.

Model

Model configuration values override any global Flask configuration.

They are applied in the SQLAlchemy model’s Meta class, omit the API_ prefix, and are written in lowercase.

Configure this level when a single model requires behaviour different from the rest of the application, such as marking a model read only, changing its serialization depth, or blocking specific methods. Options correspond directly to the global keys but in lowercase without the prefix (for example rate_limit or pagination_size_default) and accept the same data types noted in the configuration table.

Example:

class Article(db.Model):
    __tablename__ = "article"

    class Meta:
        rate_limit = "10 per second"         # API_RATE_LIMIT in Flask config
        pagination_size_default = 10           # API_PAGINATION_SIZE_DEFAULT
        blocked_methods = ["DELETE", "POST"]  # API_BLOCK_METHODS

See the Model page for more information.

Model Method

Model method configuration values have the highest priority and override all other configuration.

They are applied in the SQLAlchemy model’s Meta class, omit the API_ prefix, are lowercase, and are prefixed with the method.

Use these settings to fine-tune behaviour for a specific model-method combination. This is useful when, for example, a model should allow GET requests with a high rate limit but restrict POST calls or customise serialization only for PATCH. Any model-level option can be adapted by prefixing it with the HTTP method name (such as get_rate_limit or post_blocked) and follows the same value types as the corresponding model option.

Example:

class Article(db.Model):
    __tablename__ = "article"

    class Meta:
        get_rate_limit = "100 per minute"    # API_GET_RATE_LIMIT
        post_blocked = True                   # API_POST_BLOCKED
        patch_serialization_depth = 1         # API_PATCH_SERIALIZATION_DEPTH

See the Model Method page for more information.

Cascade delete settings

See Cascade deletes in the advanced configuration guide for usage examples of API_ALLOW_CASCADE_DELETE, API_ALLOW_DELETE_RELATED and API_ALLOW_DELETE_DEPENDENTS.

Complete Configuration Reference

API_CREATE_DOCS

default: True type bool Optional Global

  • Controls whether ReDoc documentation is generated automatically. Set to False to disable docs in production or when using an external documentation tool. Accepts True or False. Example: tests/test_flask_config.py.

API_DOCUMENTATION_HEADERS

default: ```` type str Optional Global

  • Extra HTML placed in the <head> of the docs page. Supply meta tags or script includes as a string or template.

API_DOCUMENTATION_URL

default: /docs type str Optional Global

  • URL path where documentation is served. Useful for mounting docs under a custom route such as /redoc. Accepts any valid path string. Example: tests/test_flask_config.py.

API_DOCS_STYLE

default: redoc type str Optional Global

  • Selects the documentation UI style. Use redoc (default) or swagger to render with Swagger UI.

API_SPEC_ROUTE

default: /openapi.json type str Optional Global

  • Path where the raw OpenAPI document is served. Override to change the URL exposed by the automatic endpoint.

API_TITLE

default: None type str Required Global

  • Sets the display title of the generated documentation. Provide a concise project name or API identifier. Example: tests/test_flask_config.py.

API_VERSION

default: None type str Required Global

  • Defines the version string shown in the docs header, helping consumers track API revisions. Example: tests/test_flask_config.py.

API_LOGO_URL

default: None type str Optional Global

  • URL or path to an image used as the documentation logo. Useful for branding or product recognition. Example: tests/test_flask_config.py.

API_LOGO_BACKGROUND

default: None type str Optional Global

  • Sets the background colour behind the logo, allowing alignment with corporate branding. Accepts any CSS colour string. Example: tests/test_flask_config.py.

API_DESCRIPTION

type str or str path Optional Global

  • Accepts free text or a filepath to a Jinja template and supplies the description shown on the docs landing page. Useful for providing an overview or dynamically generated content using {config.xxxx} placeholders. Example: tests/test_flask_config.py.

API_KEYWORDS

default: None Optional Global

API_CONTACT_NAME

default: None type str Optional Global

  • Human-readable name for API support or maintainer shown in the docs. Leave None to omit the contact block. Example: tests/test_flask_config.py.

API_CONTACT_EMAIL

default: None type str Optional Global

  • Email address displayed for support requests. Use when consumers need a direct channel for help. Example: tests/test_flask_config.py.

API_CONTACT_URL

default: None type str Optional Global

API_LICENCE_NAME

default: None type str Optional Global

  • Name of the licence governing the API, e.g., MIT or Apache-2.0. Helps consumers understand usage rights. Example: tests/test_flask_config.py.

API_LICENCE_URL

default: None type str Optional Global

API_SERVER_URLS

default: None type list[dict] Optional Global

  • List of server objects defining environments where the API is hosted. Each dict may include url and description keys. Ideal for multi-environment setups. Example: tests/test_flask_config.py.

API_DOC_HTML_HEADERS

default: None type str Optional Global

  • HTML <head> snippets inserted into the documentation page. Use to add meta tags or analytics scripts. Example: tests/test_flask_config.py.

API_DOC_HTML_FOOTERS

default: None type str Optional Global

  • HTML <footer> snippets rendered at the bottom of the docs page, useful for legal notices or navigation links.

API_PREFIX

default: /api type str Optional Global

  • Base path prefix applied to all API routes. Adjust when mounting the API under a subpath such as /v1. Example: tests/test_flask_config.py.

API_CACHE_TYPE

default: None type str Optional Global

  • Flask-Caching backend used for caching GET responses. Examples include SimpleCache and RedisCache. Requires the flask-caching package.

API_CACHE_TIMEOUT

default: 300 type int Optional Global

  • Expiry time in seconds for cached responses. Only applicable when API_CACHE_TYPE is set.

API_ENABLE_CORS

default: False type bool Optional Global

  • Enables Cross-Origin Resource Sharing using flask-cors so browser clients from other origins can access the API.

API_XML_AS_TEXT

default: False type bool Optional Global

  • When True, XML responses are served with text/xml instead of application/xml for broader client compatibility.

API_VERBOSITY_LEVEL

default: 1 type int Optional Global

API_ENDPOINT_CASE

default: kebab type string Optional Global

  • Case style for generated endpoint URLs such as kebab or snake. Choose to match your project’s conventions. Example: tests/test_flask_config.py.

API_ENDPOINT_NAMER

default: endpoint_namer type callable Optional Global

  • Function that generates endpoint names from models. Override to customise URL naming behaviour.

API_FIELD_CASE

default: snake type string Optional Global

  • Determines the case used for field names in responses, e.g., snake or camel. Helps integrate with client expectations. Example: tests/test_flask_config.py.

API_SCHEMA_CASE

default: camel type string Optional Global

  • Naming convention for generated schemas. Options include camel or snake depending on tooling preferences. Example: tests/test_flask_config.py.

API_PRINT_EXCEPTIONS

default: True type bool Optional Global

  • Toggles Flask’s exception printing in responses. Disable in production for cleaner error messages. Options: True or False.

API_BASE_MODEL

default: None type Model Optional Global

  • Root SQLAlchemy model used for generating documentation and inferring defaults. Typically the base db.Model class.

API_BASE_SCHEMA

default: AutoSchema type Schema Optional Global

  • Base schema class used for model serialization. Override with a custom schema to adjust marshmallow behaviour. Example: tests/test_flask_config.py.

API_AUTO_VALIDATE

default: True type bool Optional Model

  • Automatically validate incoming data against field types and formats. Disable for maximum performance at the risk of accepting invalid data.

API_GLOBAL_PRE_DESERIALIZE_HOOK

default: None type callable Optional Global

  • Callable run on the raw request body before deserialization. Use it to normalise or sanitize payloads globally.

API_ALLOW_CASCADE_DELETE

Optional

  • Allows cascading deletes on related models when a parent is removed. Use with caution to avoid accidental data loss. Example: tests/test_flask_config.py.

API_IGNORE_UNDERSCORE_ATTRIBUTES

default: True type bool Optional Model

API_SERIALIZATION_TYPE

Optional

  • Output format for serialized data. Options include url (default), json, dynamic and hybrid. Determines how responses are rendered. Example: tests/test_flask_config.py.

API_SERIALIZATION_DEPTH

Optional

  • Depth for nested relationship serialization. Higher numbers include deeper related objects, impacting performance.

API_DUMP_HYBRID_PROPERTIES

default: True type bool Optional Model

  • Includes hybrid SQLAlchemy properties in serialized output. Disable to omit computed attributes. Example: tests/test_flask_config.py.

API_ADD_RELATIONS

default: True type bool Optional Model

API_PAGINATION_SIZE_DEFAULT

default: 20 type int Optional Global

  • Default number of items returned per page when pagination is enabled. Set lower for lightweight responses. Example: tests/test_api_filters.py.

API_PAGINATION_SIZE_MAX

default: 100 type int Optional Global

  • Maximum allowed page size to prevent clients requesting excessive data. Adjust based on performance considerations.

API_READ_ONLY

default: True type bool Optional Model

API_ALLOW_ORDER_BY

default: True type bool Optional Model

API_ALLOW_FILTER

default: True type bool Optional Model

  • Allows filtering using query parameters. Useful for building rich search functionality. Also recognised as API_ALLOW_FILTERS. Example: tests/test_flask_config.py.

API_ALLOW_JOIN

default: False type bool Optional Model

  • Enables join query parameter to include related resources in queries.

API_ALLOW_GROUPBY

default: False type bool Optional Model

  • Enables groupby query parameter for grouping results.

API_ALLOW_AGGREGATION

default: False type bool Optional Model

  • Allows aggregate functions like field|label__sum for summarising data.

API_ALLOW_SELECT_FIELDS

default: True type bool Optional Model

API_ALLOWED_METHODS

default: [] type list[str] Optional Model

  • Explicit list of HTTP methods permitted on routes. Only methods in this list are enabled.

API_BLOCK_METHODS

default: [] type list[str] Optional Model

  • Methods that should be disabled even if allowed elsewhere, e.g., ["DELETE", "POST"] for read-only APIs.

API_AUTHENTICATE

Optional

  • Enables authentication on all routes. When provided, requests must pass the configured authentication check. Example: tests/test_authentication.py.

API_AUTHENTICATE_METHOD

Optional

  • Name of the authentication method used, such as jwt or basic. Determines which auth backend to apply. Example: tests/test_authentication.py.

API_CREDENTIAL_HASH_FIELD

default: None type str Optional Global

  • Field on the user model storing a hashed credential for API key auth. Required when using api_key authentication.

API_CREDENTIAL_CHECK_METHOD

default: None type str Optional Global

  • Name of the method on the user model that validates a plaintext credential, such as check_password.

API_KEY_AUTH_AND_RETURN_METHOD

default: None type callable Optional Global

  • Custom function for API key auth that receives a key and returns the matching user object.

API_USER_LOOKUP_FIELD

default: None type str Optional Global

  • Attribute used to locate a user, e.g., username or email.

API_CUSTOM_AUTH

default: None type callable Optional Global

  • Callable invoked when API_AUTHENTICATE_METHOD includes "custom". It must return the authenticated user or None.

API_USER_MODEL

Optional

API_GLOBAL_SETUP_CALLBACK

default: None type callable Optional Global

  • Runs before any model-specific processing. Use method-specific variants like API_GET_GLOBAL_SETUP_CALLBACK to target individual HTTP methods.

API_FILTER_CALLBACK

default: None type callable Optional Model

  • Adjusts the SQLAlchemy query before filters or pagination are applied.

API_ADD_CALLBACK

default: None type callable Optional Model

  • Invoked prior to committing a new object to the database.

API_UPDATE_CALLBACK

default: None type callable Optional Model

  • Called before persisting changes to an existing object.

API_REMOVE_CALLBACK

default: None type callable Optional Model

  • Executed before deleting an object from the database.

API_SETUP_CALLBACK

default: None type callable Optional Model Method

API_RETURN_CALLBACK

default: None type callable Optional Model Method

API_ERROR_CALLBACK

default: None type callable Optional Global

API_DUMP_CALLBACK

default: None type callable Optional Model Method

  • Post-serialization hook to adjust data after Marshmallow dumping.

API_FINAL_CALLBACK

default: None type callable Optional Global

  • Executes just before the response is serialized and returned to the client.

API_ADDITIONAL_QUERY_PARAMS

default: None type list[dict] Optional Model Method

  • Extra query parameters supported by the endpoint. Each dict may contain name and schema keys. Example: tests/test_flask_config.py.

API_DUMP_DATETIME

default: True type bool Optional Global

API_DUMP_VERSION

default: True type bool Optional Global

API_DUMP_STATUS_CODE

default: True type bool Optional Global

API_DUMP_RESPONSE_MS

default: True type bool Optional Global

  • Adds the elapsed request processing time in milliseconds to each response.

API_DUMP_TOTAL_COUNT

default: True type bool Optional Global

  • Includes the total number of available records in list responses, aiding pagination UX.

API_DUMP_NULL_NEXT_URL

default: True type bool Optional Global

API_DUMP_NULL_PREVIOUS_URL

default: True type bool Optional Global

API_DUMP_NULL_ERRORS

default: True type bool Optional Global

  • Ensures an errors key is always present in responses, defaulting to null when no errors occurred. Example: tests/test_flask_config.py.

API_RATE_LIMIT

default: None type str Optional Model Method

API_RATE_LIMIT_CALLBACK

default: None type callable Optional Global

  • Reserved hook that would fire when a request exceeds its rate limit. The callable could log the event or return a bespoke response. Currently, flarchitect does not invoke this callback, so setting it has no effect.

API_RATE_LIMIT_STORAGE_URI

default: None type str Optional Global

  • URI for the rate limiter’s storage backend, e.g., redis://127.0.0.1:6379. When omitted, flarchitect probes for Redis, Memcached, or MongoDB and falls back to in-memory storage. Use this to pin rate limiting to a specific service instead of auto-detection.

IGNORE_FIELDS

default: None type list[str] Optional Model Method

  • Intended list of attributes hidden from both requests and responses. Use it when a column should never be accepted or exposed, such as internal_notes. At present the core does not process this flag, so filtering must be handled manually.

IGNORE_OUTPUT_FIELDS

default: None type list[str] Optional Model Method

  • Fields accepted during writes but stripped from serialized responses—ideal for secrets like password. This option is not yet wired into the serializer; custom schema logic is required to enforce it.

IGNORE_INPUT_FIELDS

default: None type list[str] Optional Model Method

  • Attributes the API ignores if clients supply them, while still returning the values when present on the model. Useful for server-managed columns such as created_at. Currently this flag is informational and does not trigger automatic filtering.

API_BLUEPRINT_NAME

default: None type str Optional Global

  • Proposed name for the Flask blueprint wrapping all API routes. The extension presently registers the blueprint as "api" regardless of this value. Treat it as a placeholder for future namespacing support.

API_SOFT_DELETE

default: False type bool Optional Global

  • Marks records as deleted rather than removing them from the database. When enabled, DELETE swaps a configured attribute to its “deleted” value unless ?cascade_delete=1 is sent.

  • Example:

    class Config:
        API_SOFT_DELETE = True
    

API_SOFT_DELETE_ATTRIBUTE

default: None type str Optional Global

  • Model column that stores the delete state, such as status or is_deleted. flarchitect updates this attribute to the “deleted” value during soft deletes. Example:

    API_SOFT_DELETE_ATTRIBUTE = "status"
    

API_SOFT_DELETE_VALUES

default: None type tuple Optional Global

  • Two-element tuple defining the active and deleted markers for API_SOFT_DELETE_ATTRIBUTE. For example, ("active", "deleted") or (1, 0). The second value is written when a soft delete occurs.

API_ALLOW_DELETE_RELATED

default: True type bool Optional Model Method

  • Historical flag intended to control whether child records are deleted alongside their parent. The current deletion engine only honours API_ALLOW_CASCADE_DELETE, so this setting is ignored. Leave it unset unless future versions reintroduce granular control.

API_ALLOW_DELETE_DEPENDENTS

default: True type bool Optional Model Method

  • Companion flag to API_ALLOW_DELETE_RELATED covering association-table entries and similar dependents. Not currently evaluated by the code base; cascade behaviour hinges solely on API_ALLOW_CASCADE_DELETE. Documented for completeness and potential future use.

GET_MANY_SUMMARY

default: None type str Optional Model Method

  • Customises the summary line for list endpoints in the generated OpenAPI spec. Example: get_many_summary = "List all books" produces that phrase on GET /books. Useful for clarifying collection responses at a glance.

GET_SINGLE_SUMMARY

default: None type str Optional Model Method

  • Defines the doc summary for single-item GET requests. get_single_summary = "Fetch one book by ID" would appear beside GET /books/{id}. Helps consumers quickly grasp endpoint intent.

POST_SUMMARY

default: None type str Optional Model Method

  • Short line describing the create operation in documentation. For instance, post_summary = "Create a new book" labels POST /books accordingly. Particularly handy when auto-generated names need clearer wording.

PATCH_SUMMARY

default: None type str Optional Model Method

  • Sets the summary for PATCH endpoints used in the OpenAPI docs. Example: patch_summary = "Update selected fields of a book". Provides readers with a concise explanation of partial updates.