Skip to main content

A reusable FastAPI application factory

Project description

FastAPI Template

A reusable FastAPI application factory packaged for quick reuse. The package exposes a single public function, create_app, which returns a fully configured FastAPI instance with logging, metrics, documentation, and health-check routes ready to go.

🚀 Quick Start

Installation

pip install horizen-fastapi-template

Usage

Create a new file (for example main.py) and bootstrap your API:

from horizen_fastapi_template import create_app

app = create_app()

Run the application with Uvicorn:

uvicorn main:app --reload

🔧 Configuration

Application behaviour is configured through environment variables using pydantic-settings. Create a .env file alongside your application if you need to override defaults:

PORT=8000
LOG_LEVEL=INFO
APP_NAME=MyFastAPIApp
PROCESS_TIME_HEADER=X-Process-Time
SWAGGER_STATIC_FILES=/static/swagger
SWAGGER_OPENAPI_JSON_URL=/openapi.json
LOG_REQUEST_EXCLUDE_PATHS=["/health", "/metrics", "/static", "/docs", "/redoc", "/openapi.json", "/.well-known"]

The same settings object is used internally to configure logging, documentation, and middleware. Although the implementation lives under fastapi_template._internal, those modules are considered private and may change without notice.

🧩 Features

  • Logging – Structured logging powered by loguru with an optional request logging middleware.
  • Monitoring – Prometheus-compatible metrics endpoint and uptime background task ready to register in your observability stack.
  • Documentation – Swagger UI and ReDoc served through customisable static assets bundled with the package.
  • Middleware – Request timing, exception handling, and request logging middleware that can be toggled through configuration flags.
  • Utilities – Helper clients for HTTP APIs, Bitbucket API, FTP servers, and Kubernetes interactions, plus shared Pydantic models for error responses.

📁 Project Structure

FastApiTemplate/
├── app/
│   └── main.py               # Example application entrypoint
├── package/
│   └── fastapi_template/
│       ├── __init__.py       # Public package exposing `create_app`
│       ├── utils.py          # Public utility functions and classes
│       ├── _internal/        # Private framework modules
│       └── static/           # Bundled static assets for Swagger UI
├── pyproject.toml            # Packaging metadata
├── requirements.txt         # Pinning dependencies for development
└── README.md

🛠️ Development

Install dependencies in editable mode when working on the package:

pip install -e .

Run the example application from the repository root:

python -m app.main

📄 License

Distributed under the terms of the MIT license. See the LICENSE file for details.

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

horizen_fastapi_template-0.0.0.3.dev1.tar.gz (742.1 kB view details)

Uploaded Source

Built Distribution

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

horizen_fastapi_template-0.0.0.3.dev1-py3-none-any.whl (748.7 kB view details)

Uploaded Python 3

File details

Details for the file horizen_fastapi_template-0.0.0.3.dev1.tar.gz.

File metadata

File hashes

Hashes for horizen_fastapi_template-0.0.0.3.dev1.tar.gz
Algorithm Hash digest
SHA256 b6826b6779717b52739e7e73f4aca6728c9988ad47dc1d6c43dbcf27d7d61a97
MD5 2b705e10788104d0160ce48f22c9bbd2
BLAKE2b-256 cf291805882eb4c74eaf255863b0907adfe0ae69231ddc0d44fb2d746a4403dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for horizen_fastapi_template-0.0.0.3.dev1.tar.gz:

Publisher: python-publish.yml on chaimmendelson/FastApiTemplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file horizen_fastapi_template-0.0.0.3.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for horizen_fastapi_template-0.0.0.3.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 32e493ff10bfdcea095d9bc80fef06dd32b72eba8094e51986019af56d004d9c
MD5 0d69cfdb65d0b6e658bac8929c08972e
BLAKE2b-256 afdd7373a1b8c31b818e8ffce25bc611e2b580f935b646131ee347564e7710c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for horizen_fastapi_template-0.0.0.3.dev1-py3-none-any.whl:

Publisher: python-publish.yml on chaimmendelson/FastApiTemplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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