Blue Firmament
中文名:碧霄 日语名:青空 (AoSora)
A backend framework for Python applications that covers all you need, and aims at building east-to-read, maintainable application.
Features
- 任务处理器
- 可以像普通函数一样调用,无需将业务逻辑和处理器拆成两个函数
- 数据模型
- 数据模型方法中可以调用管理器的方法:
Manager(self._task_context)(得继承同一个TaskContext) - 通过 dump_flag,不必为了 create, edit 去维护变体
在创建只需
**data.dump_to_dict(),编辑只需merge_scheme即可将用户提交的新值保存
- 数据模型方法中可以调用管理器的方法:
- DAL
- 支持TableLike, KVLike, PubSubLike数据源
- 支持鉴权(与会话同步)
- 具体支持 PostgREST, Redis 数据源
- 自动处理引用表查询 (A表引用B表,查询A表时直接使用 B.column.
Installation
pip install blue-firmament
Example
# main.py
import blue_firmament
# 获取日志器
import blue_firmament.log
logger = blue_firmament.log.get_logger(__name__)
# 覆盖设置
from data.settings.base import get_setting as get_base_setting
from data.settings.dal import get_setting as get_dal_setting
import blue_firmament.main
from blue_firmament.transport.http import HTTPTransporter
from blue_firmament.session.common import CommonSession
app = blue_firmament.main.BlueFirmamentApp()
# 添加一个传输层
app.add_transporter(HTTPTransporter(
app.handle_request, CommonSession,
host=get_base_setting().http_host, port=get_base_setting().http_port,
))
logger.info("Initializing BlueFirmament's Routers and Middlewares...")
# 配置数据访问层
from blue_firmament.dal import set_anon_dao
from blue_firmament.dal.postgrest_dal import PostgrestDataAccessObject
# 配置一个全局的ANON角色的PostgrestDAO实例,会话在无法获取到权限的时候会fallback到此
set_anon_dao(PostgrestDataAccessObject(
token=get_dal_setting().postgrest_anonymous_token,
), PostgrestDataAccessObject)
# 声明数据模型
from blue_firmament.transport import TransportOperationType
from app.schemas.main import AccountProfile
# 基于数据模型添加CRUD服务
app.provide_crud_over_scheme('account', disabled_operations=(TransportOperationType.DELETE,))(AccountProfile)
# 启动服务
app.run()
Manager
# manager.py
import typing
from blue_firmament import listen_to, Method
from blue_firmament.manager import CommonManager
from blue_firmament.scheme import BusinessScheme
from blue_firmament.scheme.enum import Status
from blue_firmament.exceptions import Forbidden
class PRStatus(Status):
DRAFT = "draft"
EXECUTING = "executing"
CANCELLED = "cancelled"
def to_cancelled(self) -> typing.Self:
return self._to_target_status(self.CANCELLED, self.DRAFT)
class PartnerRequest(BusinessScheme[int]):
status: PRStatus
created_by: str
def is_admin(self, account_id: str) -> bool:
return self.created_by == account_id
class PartnerRequestManager(CommonManager[PartnerRequest, int]):
async def _must_be_admin(
self,
pr_id: None | int = None,
) -> None:
self._scheme = await self._get_scheme(_id=pr_id)
if not self._scheme.is_admin(self._operator.id):
raise Forbidden("must be admin")
@listen_to(Method.PUT, '/{pr_id}/cancel')
async def cancel(
self,
pr_id: int
):
self._scheme = self._get_scheme(pr_id)
await self._must_be_admin()
self._scheme.status.to_cancelled()
await self._update_scheme()
self._emit(".cancelled", pr_id=self._scheme._id)
return self._scheme
Documentation
To build the documentation:
# Install documentation dependencies
pip install -e ".[docs]"
# Build the documentation
cd docs
make html
After building, the documentation will be available in docs/_build/html.
Metadata
Release files for blue-firmament 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| blue_firmament-0.2.1.tar.gz | 94.9 kB | With provenance | Details for blue_firmament-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blue_firmament-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for blue_firmament-0.2.1-py3-none-any.whl |
Total release size: 217.7 kB
Release files / blue_firmament-0.2.1.tar.gz
| Download URL | blue_firmament-0.2.1.tar.gz |
|---|---|
| Size | 94.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a441bc5f406db6a411fda26ffa166a0c0ddc392ce3d34beca72126743bda4f2
|
|
BLAKE2b-256 checksum How to use checksums |
f2450aef8550dc8e7db393b0e6148442ac7af13cf1d7a351b4efd7d63464e321
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2025.
Transparency logRelease files / blue_firmament-0.2.1-py3-none-any.whl
| Download URL | blue_firmament-0.2.1-py3-none-any.whl |
|---|---|
| Size | 122.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0db56345cca7a514ec43348487e374bb5048178816bb9f814d09687cc933a0e6
|
|
BLAKE2b-256 checksum How to use checksums |
29ba2c17c83d8041df76d5878a88ff50890363a929bbfaa600e52098de40e342
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2025.
Transparency logSecurity for blue-firmament 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for blue_firmament-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.