Skip to main content

Provides several modules that help improve web application development using FastAPI

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastwings-0.0.18.tar.gz (47.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastwings-0.0.18-py3-none-any.whl (46.6 kB view details)

Uploaded Python 3

File details

Details for the file fastwings-0.0.18.tar.gz.

File metadata

  • Download URL: fastwings-0.0.18.tar.gz
  • Upload date:
  • Size: 47.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastwings-0.0.18.tar.gz
Algorithm Hash digest
SHA256 0db92d9bfd698cb41fc008a052af667f0a820b92779690277950eac817debb4f
MD5 07b12ff5755a97c74322ffeffa6bfd40
BLAKE2b-256 9387483377f51086bc6b1bdbb067d361274606404502b24aa5125237e6c1094c

See more details on using hashes here.

File details

Details for the file fastwings-0.0.18-py3-none-any.whl.

File metadata

  • Download URL: fastwings-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 46.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastwings-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 3497e6a24772f852729561bd014d63b81f108e469eecbbfefac58a404ab8391c
MD5 a62d1cd35c8239cec8ada2b22b0810bc
BLAKE2b-256 9784f88a7beb3d98f481bbe35e988f243e54feccf9e67662f8ab9717eb71b692

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page