What¶

FastAPI Hive Framework, modulization of code layout, decoupling codes into foundations and endpoints, developer-friendly, easy to be integrated
Introduction:¶
Regular fastapi project setups some folders for storing specific function codes, such as router folder for api registering folder and model folder for defining db tables and pydantic data model.
So one service codes have to be splitted and exist in several folders, the problem is the code-review issue of looking for them with jumpping different folders again and again.
If you feel it is tiresome task like me, then FastAPI Hive is just for you.
Every bee is thought as the entity of one service codes, defined as endpoints, including all function codes(router, model). FastAPI Hive is the container(bee's home) for all bees.
Also for these common function code, like database setup and authentication codes, they are defined as foundations, the structure the hive is built on. Every function code is put into one foundation folder together.
Documentation: https://fanqingsong.github.io/fastapi-hive
Source Code: https://github.com/fanqingsong/fastapi-hive
PYPI: https://pypi.org/project/fastapi-hive/
FastAPI Hive Framework is a developer friendly and easy to be integrated framework for managing your code by endpoints and foundations folder structure.
The key features are:
- Foundation Container: a top-level folder to layout codes by function folder, like db and authentication.
- Endpoint Container: a top-level folder to layout service codes by endpoint folder,
- Endpoint folder: a sub-folder in Endpoint Container, layout one service code by function folder(router, db, service, etc).
- Explicit router mounting: each endpoint includes its
APIRouterfromstartupwithself.app.include_router(...). - Model Preloading Easily: the service(such as ML model) defined by module will be mounted into app easily, in order to reduce loading time during endpoint request.
- Developer-Friendly: all one-endpoint/foundation codes are put in one same folders, easy to review and update.
- Easy-to-be-Integrated: Just several line codes to integrate it in your app.
estimation based on tests by author with this project**, have a look at example folder.
Overview¶
Folders are set in such layout. Each endpoint chooses its URL prefix when it mounts the router.

Requirements¶
Python 3.8–3.13
FastAPI Hive Framework stands on the shoulders of giants:
- FastAPI web framework.
Have a Try¶
Installation¶
Install from the local checkout. The package published on PyPI can lag behind this repository.
First, git clone this repo.
Second, install the library from the local source.
Note: If you just treat it as a library, and want to integrate it into your app, you can just run this command.
install dependency packages¶
Third, install the required packages for running demo in your local environment (ideally virtualenv, conda, etc.). Note: You can reference demo code to make up your own app in anywhere.
Setup¶
-
Duplicate the
example/.env.examplefile and rename it toexample/.env -
In the
example/.envfile configure theAPI_KEYentry. The key is used for authenticating our API.
A sample API key can be generated using Python REPL:
Run app¶
Start the example from this repository so it uses the local checkout, not the PyPI release.
The same local install and startup sequence is make run-example.
production running command:
-
Go to http://localhost:8000/docs.
-
Click
Authorizeand enter the API key as created in the Setup step.
-
You can use the sample payload from the
docs/sample_payload.jsonfile when trying out the house price prediction model using the API.
Run Tests¶
If you're not using tox, please install with:
Run your tests with:
This runs the configured test, coverage, and code-quality environments.
Package and Upload¶
For maintainer of this project, please follow: Before these action, change version in setup.py