Skip to main content

Tools2Fast FastAPI

Shared tools, mixins, and base services for FastAPI applications. Designed for internal use by the Solautyc Team to standardize model definitions and common services across multiple packages.

📖 Conventions reference: this package follows the 2fast-handbook for ecosystem conventions (structure, versioning, README, commits, release).

Installation

You can install this package from PyPI (if published) or use it locally within your workspace:

pip install tools2fast-fastapi

Locally with UV:

uv pip install -e path/to/tools2fast-fastapi

Features

  • SQLModel Mixins: Standardized IdMixin, TimestampMixin, and AuditMixin.
  • Base Models: Core models setup to be inherited across all entity definitions.
  • Unified API envelope: Success and error helpers via APIResponse.
  • Auth error helper: APIResponse.auth_error(...) returns a ready-to-return JSONResponse with the project envelope and, for HTTP 401, the RFC 6750 WWW-Authenticate header.
  • Shared Services: Reusable services logic for basic CRUD and related queries (coming soon).

Auth error contract

APIResponse.auth_error produces a stable contract for authentication and authorization failures. The discriminator is error.type (never the message), which lets clients react without string matching:

from tools2fast_fastapi import APIResponse

return APIResponse.auth_error(
    error_code="TokenExpired",
    message="Token expirado",
    status_code=401,
    www_authenticate='Bearer error="expired_token"',
)

When the failure happens inside a FastAPI dependency, return a Response is not enough (FastAPI injects it as the dependency value instead of short-circuiting). Raise AuthError and register the handler once at startup:

from fastapi import FastAPI
from tools2fast_fastapi import AuthError, install_auth_error_handler

app = FastAPI()
install_auth_error_handler(app)

async def get_current_user(...):
    raise AuthError(
        error_code="TokenExpired",
        message="Token expirado",
        www_authenticate='Bearer error="expired_token"',
    )

Both paths produce the same envelope and the same RFC 6750 header.

Situation Status error.type WWW-Authenticate
Missing token 401 TokenMissing Bearer
Malformed / bad signature 401 TokenInvalid Bearer error="invalid_token"
Expired token 401 TokenExpired Bearer error="expired_token"
Email not verified 403 EmailNotVerified —
Missing permission 403 PermissionDenied —
Missing role 403 RoleMissing —
Valid token, no tenant 403 TenantRequired —
Inactive tenant 403 TenantInactive —

When status_code is 401 and www_authenticate is omitted, the header defaults to Bearer. For any other status the header is omitted unless passed explicitly.

Documentation

See the docs/ folder for more detailed instructions and usage guides:

Examples

Check the examples/ folder for sample implementation.

License

This project is licensed under the MIT License.

Metadata

Release files for tools2fast-fastapi 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tools2fast-fastapi 0.4.0
File Size Uploaded Provenance Actions
tools2fast_fastapi-0.4.0.tar.gz 36.5 kB Without provenance Details for tools2fast_fastapi-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tools2fast-fastapi 0.4.0
File Interpreter ABI Platform Actions
tools2fast_fastapi-0.4.0-py3-none-any.whl Python 3 none any Details for tools2fast_fastapi-0.4.0-py3-none-any.whl

Total release size: 67.2 kB

Release files / tools2fast_fastapi-0.4.0.tar.gz

Download URL tools2fast_fastapi-0.4.0.tar.gz
Size 36.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e14d507a71b5ff1d026c84839f8654a78889581fb847fbf2cb0fb5a7d5f2cd45
BLAKE2b-256 checksum
How to use checksums
367156077e1ab415da37736d950f5b98af6c56e7ba06b1f334c2fb2aa705d06a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / tools2fast_fastapi-0.4.0-py3-none-any.whl

Download URL tools2fast_fastapi-0.4.0-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c0ee35d616a6d657ea99bd782457ad4969763aab93b1440f7d6b84b3e3a1a25
BLAKE2b-256 checksum
How to use checksums
b4c6a352b5b21f0390413bb9e7d4054e33d0a53ceeede6014e8a8294ade6236e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for tools2fast-fastapi 0.4.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page