Skip to main content

backbone-api

OpenAPI request and response models

Installation & Upgrade

pip install basalam.backbone-api

TODO List

  • Add Message Toast Field
  • Add Pagination Query Params Dependency

Usage Example

import uvicorn
from fastapi import APIRouter
from fastapi import FastAPI
from pydantic import BaseModel

from basalam.backbone_api.responses import (
    ForbiddenResponse,
    NotFoundResponse,
    UnauthorizedResponse,
    UnprocessableContentResponse,
    BulkResponse, ConflictResponse
)

app = FastAPI()


class User(BaseModel):
    id: int
    name: str


router = APIRouter(responses={
    401: {"model": UnauthorizedResponse},
    403: {"model": ForbiddenResponse},
    404: {"model": NotFoundResponse},
    409: {"model": ConflictResponse},
    422: {"model": UnprocessableContentResponse}
})


@router.get("/", response_model=BulkResponse[User])
async def root():
    ls = [
        User(id=1, name="John Doe"),
        User(id=2, name="Jane Boe")
    ]
    return BulkResponse(data=ls).as_json_response()

app.include_router(router)
if __name__=="__main__":
    uvicorn.run(app, host="localhost", port=8000)

Using Exceptions

in app.py

from fastapi import FastAPI
from basalam.backbone_api.exceptions.client_error.handlers import client_error_exception_handler
from basalam.backbone_api.exceptions.client_error import (
    ClientErrorException,
    ForbiddenException,
    UnauthorizedException,
    ConflictException,
    NotFoundException,
    UnprocessableEntityException
)

app = FastAPI()

exception_handlers = {
    ClientErrorException: client_error_exception_handler,
    ForbiddenException: client_error_exception_handler,
    UnauthorizedException: client_error_exception_handler,
    ConflictException: client_error_exception_handler,
    NotFoundException: client_error_exception_handler,
    UnprocessableEntityException: client_error_exception_handler,
}

...

If you raise any of these exceptions everywhere in you FastAPI project FastAPI will return a client error response based on the excpetion.

Example Usage

def view_or_somthing_else():
    raise ForbiddenException()

Credits

This project was inspired by the work of Mr.MohammadAli Soltanipoor on OpenAPI.

Metadata

Release files for basalam.backbone-api 0.2.3

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

Source distribution (sdist)

Source distribution for basalam.backbone-api 0.2.3
File Size Uploaded Provenance Actions
basalam_backbone_api-0.2.3.tar.gz 8.8 kB Without provenance Details for basalam_backbone_api-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for basalam.backbone-api 0.2.3
File Interpreter ABI Platform Actions
basalam.backbone_api-0.2.3-py3-none-any.whl Python 3 none any Details for basalam.backbone_api-0.2.3-py3-none-any.whl

Total release size: 25.8 kB

Release files / basalam_backbone_api-0.2.3.tar.gz

Download URL basalam_backbone_api-0.2.3.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c930b78d3905bdfd3ee7a45b84d7853c1a884446cde0aa38e29250e67240535c
BLAKE2b-256 checksum
How to use checksums
ea3a1d00d795984f838b273c77a83692bf00040d4ec7d478af943ae5f80a4e1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / basalam.backbone_api-0.2.3-py3-none-any.whl

Download URL basalam.backbone_api-0.2.3-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
039ba72a0e8f8e7a9aedfc35c9b6aaed00a53981cfe1aa6133a01b08fcdecd4d
BLAKE2b-256 checksum
How to use checksums
6c2279dc48c19ca75df8b562a1192bf73793ab5cbb6bd6e6030e1318ca5c1e74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Security for basalam.backbone-api 0.2.3

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