FastAPI Middleware Library
A reusable FastAPI middleware library for implementing cross‑cutting concerns such as logging, authentication, observability, or request/response transformation.
✨ Highlights
🚀 Native FastAPI / ASGI middleware ⚙️ Fully async and non‑blocking 🧩 Modular and extensible design 📦 Lightweight with minimal dependencies 🛠️ Easy to integrate and customize
📦 Installation Shellpip install fastapi-middleware-libraryShow more lines Or install from source: Shellgit clone https://github.com//.gitcd pip install -e .Show more lines
🚀 Quick Start Pythonfrom fastapi import FastAPIfrom fastapi_middleware_library import ExampleMiddlewareapp = FastAPI()app.add_middleware( ExampleMiddleware, enabled=True,)Show more lines
⚙️ Configuration
OptionTypeDefaultDescriptionenabledboolTrueEnable or disable middlewareconfigdict{}Custom configuration options
ℹ️ Replace or extend with real configuration options as the API evolves.
🧠 How It Works This middleware integrates into FastAPI’s ASGI lifecycle and intercepts:
Incoming HTTP requests Request processing before route execution Outgoing responses
It is designed to be:
Side‑effect aware Async safe Composable with other middleware
📁 Project Structure Plain Text.├── fastapi_middleware_library/│ ├── init.py│ └── middleware.py├── tests/├── docs/├── pyproject.toml├── README.md├── LICENSE└── CONTRIBUTING.mdShow more lines
🧪 Development Setup Shellpython -m venv .venvsource .venv/bin/activatepip install -r requirements-dev.txtShow more lines Run tests ShellpytestShow more lines Linting & formatting Shellruff .black .Show more lines
🛣️ Roadmap
Stable public API Typed configuration models Logging & tracing hooks Example FastAPI app Performance benchmarks Documentation site
🤝 Contributing Contributions are welcome and appreciated! Please:
Fork the repository Create a feature branch Add tests for new behavior Open a Pull Request
See ./CONTRIBUTING.md for details.
🔐 Security If you discover a security issue, please do not open a public issue. Instead, report it privately following the instructions in SECURITY.md.
📄 License This project is licensed under the MIT License. See ./LICENSE for details.
🙏 Acknowledgements Built with ❤️ on top of:
https://fastapi.tiangolo.com/ The ASGI specification
If you want, I can also:
Add GitHub badges (CI, coverage, PyPI) Write a CONTRIBUTING.md or SECURITY.md Create a real middleware example Tune wording for corporate or foundation‑backed OSS
Just tell me what level of polish you want.