A library for creating modular FastAPI applications.
Project description
FastAPI Blocks
fastapi-blocks is a Python package that allows you to structure your FastAPI applications using a modular "blocks" architecture. Each block is a self-contained component with its own routes, static files, and templates. This makes it easy to develop and maintain large FastAPI applications by breaking them down into smaller, reusable pieces.
Installation
pip install fastapi-blocks
Then run
python -m fastapi_blocks setup -f BLOCKS_FOLDER
*Replace BLOCKS_FOLDER with path to blocks folder from root
Updating blocks
python -m fastapi_blocks update
Additional flags:
- -A - Auto-install pip packages from blocks
- -S - Save block hashes
- -V - Do not verify block hashes (Default is to verify)
Examples
Example Block
- Example Block - An example block
Example Project
- Example Project - An example project
Reserved Words
Variable names
router- In router files, the variable router is used to searche for router to include into app.
Template names
How to
Register Jinja funcs for shared templates
In order to allow other blocks to access functions via jinja, you would need to add the functions via hook into BlockManager().templates_globals, the key being the name of the function to call from jinja, and the value being the function itself.
eg.
def register_jinja_funcs(**kwargs):
from fastapi_blocks import BlockManager
BlockManager().templates_globals['has_role'] = has_role
class Settings(BlockSettingsMixin):
additional_user_roles : Optional[List[str]] = Field(description="Additional user roles to add", default=None)
def _start_hooks(self) -> List:
return super()._start_hooks() + [register_jinja_funcs]
Then, make sure that the block_config.toml has an entry for extra_block_settings with the name of the python file as value. .ie for 'settings.py', it would be settings.
Once that is done, you will need to run setup so that the blockmanager toml is updated.
In some other block, you would then be able to call the function from jinja as long as it is using templates from BlockManager.
If you want to use jinja within a blocks jinja2env, you'd have to get the template_globals from blockmanager then add them to the jinja2env's globals.
Todo:
- Put more meaningful tests
- Add command to setup templates/default
- Add todos
- Add some sort of security check
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_blocks-0.1.5.tar.gz.
File metadata
- Download URL: fastapi_blocks-0.1.5.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80ff757acc7ccff76388cb1a9bbca0055ffa48c1181397bf54d52cdcdbddb040
|
|
| MD5 |
a079ca611fce25d76ee9ab2b1d0ba2d4
|
|
| BLAKE2b-256 |
148cea49ac7c8813cc01fe3aeb770c223d4ee6f02cdedd138f12440936aa3b42
|
Provenance
The following attestation bundles were made for fastapi_blocks-0.1.5.tar.gz:
Publisher:
python-publish.yml on r3sbarra/fastapi-blocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_blocks-0.1.5.tar.gz -
Subject digest:
80ff757acc7ccff76388cb1a9bbca0055ffa48c1181397bf54d52cdcdbddb040 - Sigstore transparency entry: 440275192
- Sigstore integration time:
-
Permalink:
r3sbarra/fastapi-blocks@fbb4189fe47ea678caa93936b0f02a66ab026bbd -
Branch / Tag:
refs/tags/0.1.5 - Owner: https://github.com/r3sbarra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fbb4189fe47ea678caa93936b0f02a66ab026bbd -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_blocks-0.1.5-py3-none-any.whl.
File metadata
- Download URL: fastapi_blocks-0.1.5-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82cd69d8e8e2c5e833b1a8414f62e45fd426eb327b3b359894520a4f817bd7e4
|
|
| MD5 |
66f600e2a3a6189974bb9521dd57e3e8
|
|
| BLAKE2b-256 |
742feb3e8c7dd6d8901c78236a3367e01279ce0ead04e56812f9c46d45d7dd1b
|
Provenance
The following attestation bundles were made for fastapi_blocks-0.1.5-py3-none-any.whl:
Publisher:
python-publish.yml on r3sbarra/fastapi-blocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_blocks-0.1.5-py3-none-any.whl -
Subject digest:
82cd69d8e8e2c5e833b1a8414f62e45fd426eb327b3b359894520a4f817bd7e4 - Sigstore transparency entry: 440275200
- Sigstore integration time:
-
Permalink:
r3sbarra/fastapi-blocks@fbb4189fe47ea678caa93936b0f02a66ab026bbd -
Branch / Tag:
refs/tags/0.1.5 - Owner: https://github.com/r3sbarra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fbb4189fe47ea678caa93936b0f02a66ab026bbd -
Trigger Event:
release
-
Statement type: