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.1

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.1
File Size Uploaded Provenance Actions
tools2fast_fastapi-0.4.1.tar.gz 37.0 kB Without provenance Details for tools2fast_fastapi-0.4.1.tar.gz

Built distribution (wheel)

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

Total release size: 68.0 kB

Release files / tools2fast_fastapi-0.4.1.tar.gz

Download URL tools2fast_fastapi-0.4.1.tar.gz
Size 37.0 kB
Tags Source
SHA-256 checksum
How to use checksums
32665781412fdb3f48b98ef31fa0286bc8784574969bac105dc99aef68f65fed
BLAKE2b-256 checksum
How to use checksums
8eaf59dbf10ca169a3564804415057d21077cca9d5cf3db0dc3575b25e639314
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.1-py3-none-any.whl

Download URL tools2fast_fastapi-0.4.1-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9ae6ff8a277f0f2dd15618828844f7ee91efe7bfc1fb4fb340e29803370d845
BLAKE2b-256 checksum
How to use checksums
a2f7ce2eb745611f0984c8f36372faa69779b0a8fc753891a45f1624fa87e6d6
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.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.

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