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

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.3.14
File Size Uploaded Provenance Actions
tools2fast_fastapi-0.3.14.tar.gz 33.7 kB Without provenance Details for tools2fast_fastapi-0.3.14.tar.gz

Built distribution (wheel)

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

Total release size: 62.3 kB

Release files / tools2fast_fastapi-0.3.14.tar.gz

Download URL tools2fast_fastapi-0.3.14.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3a6bd5dba1ee29cbfe6acb6e6ff46792ff5ad21a98fdd8575d7bb17a3f5f50e6
BLAKE2b-256 checksum
How to use checksums
2eb68a8367ee5f9991d424fca356264d17299ac2bd0e362118f7a0020d3bccfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

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

Download URL tools2fast_fastapi-0.3.14-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f62de92bdc82cc5d9a9ef94629d75b93d9cfad253d3485fbe83b4ece78b862d
BLAKE2b-256 checksum
How to use checksums
8e269bb8b782df58ff9d3c66bc0f20d9324bfe991eb11c87d25e9f079e29bc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Security for tools2fast-fastapi 0.3.14

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