Brickworks
Brickworks is a modular, "batteries included" backend Framework, build on FastAPI and SQLAlchemy.
Key features:
- Modular and fully async, build on FastAPI
- Multi-tenancy with schema separation
- Policy Based Access Control (PBAC)
- Role Based Access Control (RBAC)
- Build in CLI for db migrations and common tasks
WARNING!!! Brickworks is currently in a very early development stage - expect things to change a lot. (You probably shouldn't use this yet.)
Basic usage
Brickworks requires your project to have a pyproject.yaml.
It is recommended to use a dependency management tool like Poetry or uv, which will create the pyproject.yaml for you and help you manage your projects dependencies.
Installation
uv init
uv add brickworks
uv pip install -e .
Create your first brick
Brickworks allows you to build your application out of individual Python modules called bricks. Each brick should encapsulate a specific functionality, making the codebase easier to understand, maintain and reuse.
To create a brick you can use the command line tool that comes with Brickworks: Mason.
mason brick create mybrick --namespace app
uv pip install -e
This will create the app package, containing the mybrick module and register your new brick in the pyproject.toml.
Add your first route
Brickworks is based on FastAPI, so routes are working the same way they would in FastAPI. Add routes to the app.mybrick.routes module...
from fastapi import APIRouter
r = APIRouter(prefix="/myroutes")
@r.get("/")
async def hello_world():
return "Hello World"
... and register them in the brick.json
{
"routers": ["app.mybrick.routers.r"],
"middlewares": [],
"loadme": []
}
Your first Database Model
Brickworks uses the ORM (Object Relational Mapper) from SQLAlchemy. All your models should inherit from the BaseDBModel class, which is an SQLAlchemy model class. This base class provides common fields and functionality that are useful for most applications, such as access control, attaching files, creating views and more!
from sqlalchemy import String, Integer
from sqlalchemy.orm import Mapped, mapped_column
from brickworks.core.models.base_dbmodel import BaseDBModel
class BookModel(BaseDBModel):
__tablename__ = "mymodule_books"
title: Mapped[str] = mapped_column(String(255), nullable=False)
author: Mapped[str] = mapped_column(String(255), nullable=False)
year_published: Mapped[int] = mapped_column(Integer, nullable=True)
# create a new book
book = await BookModel(
title="The Hobbit", author="J.R.R. Tolkien", year_published=1937
).persist()
# get books by author
books = await BookModel.get_list(author="J.R.R. Tolkien")
To run database migrations you can just use Mason:
mason db upgrade
Which will create migration files using alembic and executes the migration.
Policy Based Access Control (PBAC)
Policies are classes that define rules for accessing or filtering resources. Policies are only applied if you access the models with the methods get_one_or_none_with_policies() or get_list_with_policies().
from brickworks.core.acl.base_policy import BasePolicy, PolicyTypeEnum
from apps.mybrick.models import BookModel
class NoTolkienBooksPolicy(BasePolicy):
policy_type = PolicyTypeEnum.RESTRICTIVE
async def filter(self, user_uuid: str | None, obj_class: type[BookModel]):
# Prevent access to books authored by J.R.R. Tolkien
return obj_class.author.notilike("J.R.R. Tolkien")
BookModel.__policies__.append(NoTolkienBooksPolicy())
Metadata
Release files for brickworks 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| brickworks-0.0.9.tar.gz | 156.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| brickworks-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 207.9 kB
Release files / brickworks-0.0.9.tar.gz
| Download URL | brickworks-0.0.9.tar.gz |
|---|---|
| Size | 156.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
265f44f2465c4b322602a6f67aeead558cdf1a8d76242bf315d55b95b948f383
|
|
BLAKE2b-256 checksum How to use checksums |
108016e6163c0354626771e3cae688b81948040764379410bad8e7f5918f5b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.12
|
Release files / brickworks-0.0.9-py3-none-any.whl
| Download URL | brickworks-0.0.9-py3-none-any.whl |
|---|---|
| Size | 51.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e52e3ad7efb22ae4d8bf849d5827b55adfe888d24e0561b47fc58816993c329
|
|
BLAKE2b-256 checksum How to use checksums |
23fc9a11a489103e0e173b6297020e3484edf546bf165d3693632dcea13d6a47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.12
|