Skip to main content

FastAPI Base

About FastAPI Base

FastAPI Base is a library based on FastAPI. It provides several modules that help improve web application development using FastAPI

Some module in project

  • Logger module
  • Authentication module
  • Database Connection module
  • CRUD module
  • Encrypt module
  • Common Design Pattern module

Install

With using the logger with 3rdParty handlers

$ pip install fastwings[logger-logstash,logger-ggchat]

Usage

Config middleware, exception_handler, logger with uvicorn

from fastwings.app import app
from fastwings.logger import configure_logger, get_uvicorn_configure_logger
from fastwings.logger.filter import HealthCheckFilter
from fastwings.logger.formatter import DEFAULT_FORMATTER
from fastwings.logger.handler.logstash_handler import LogStashHandler
from fastwings.logger.handler.file_handler import FileHandler
from fastwings.logger.handler.stdout_handler import StdoutHandler
from fastwings.middleware.common_handler import timer_middleware
from fastwings.middleware.exception_handler import business_exception_handler
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.cors import CORSMiddleware


# Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
    expose_headers=["*"],
)

# Add Timer middleware
app.add_middleware(BaseHTTPMiddleware, dispatch=timer_middleware)

# Add Business Exception Handler
app.add_exception_handler(BusinessException, business_exception_handler)

configure_logger(
    handlers=[
        ("builtin", StdoutHandler(log_format=DEFAULT_FORMATTER)),
        ("builtin", FileHandler(log_format=DEFAULT_FORMATTER, log_filter=HealthCheckFilter())),
        ("custom", LogStashHandler(service_name="Test", log_filter=HealthCheckFilter()))
    ]
)


logger = logging.getLogger(__name__)


@app.post('/test')
async def test(
    title: str = Form(...),
    description: str = Form(...),
) -> ResponseObject:
    """ doc """
    logger.info(f"{title}-{description}")
    return ResponseObject(data=f"{title}-{description}")


uvicorn.run(
    app,
    host="0.0.0.0",
    port=3000,
    workers=1,
    reload=False,
    log_config=get_uvicorn_configure_logger()
)

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Metadata

Release files for fastwings 0.0.18

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

Source distribution (sdist)

Source distribution for fastwings 0.0.18
File Size Uploaded
fastwings-0.0.18.tar.gz 47.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastwings 0.0.18
File Interpreter ABI Platform
fastwings-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 94.4 kB

Release files / fastwings-0.0.18.tar.gz

Download URL fastwings-0.0.18.tar.gz
Size 47.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0db92d9bfd698cb41fc008a052af667f0a820b92779690277950eac817debb4f
BLAKE2b-256 checksum
How to use checksums
9387483377f51086bc6b1bdbb067d361274606404502b24aa5125237e6c1094c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastwings-0.0.18-py3-none-any.whl

Download URL fastwings-0.0.18-py3-none-any.whl
Size 46.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3497e6a24772f852729561bd014d63b81f108e469eecbbfefac58a404ab8391c
BLAKE2b-256 checksum
How to use checksums
9784f88a7beb3d98f481bbe35e988f243e54feccf9e67662f8ab9717eb71b692
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.0.18 This release

2 release files

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