Canary Framework — lightweight decorator-driven Python service framework
Reason this release was yanked:
0.4版本进行了破坏性重构,我做了很多更好的设计
Project description
Canary Framework
Lightweight Python Service Framework — Decorator-Driven, Zero Boilerplate
Canary Framework is a decorator-driven service framework. Core philosophy: Services are the minimum unit. Modules compose services. Modules themselves are also services.
Features
- Decorator API —
@service/@module, no base class inheritance needed - Topological Startup — Kahn's algorithm ensures dependencies start first
- Dependency Injection —
deps=[DBService]auto-injected asself.db_service - Config Management — pydantic-settings +
app.config(config=...), auto-reads.envand env vars - Lifecycle Hooks —
@on_config/@on_init/@on_start/@on_end, sync/async adaptive - Web Integration —
WebCanaryfor one-click FastAPI + Uvicorn - Log Sanitization — sensitive config fields (password, secret, token) automatically masked
Installation
pip install canary-framework # core library
pip install canary-framework[web] # with FastAPI support
Quick Start
import asyncio
from canary_framework import service, module, on_start, Canary
@service(name="hello")
class HelloService:
@on_start
def start(self) -> None:
print("Hello from Canary!")
@module(name="App", services=[HelloService])
class App:
pass
async def main() -> None:
app = Canary(App)
await app.config()
await app.init()
await app.start()
asyncio.run(main())
Web Example
import asyncio
from pydantic import BaseModel
from canary_framework import service, module, on_config, on_start, Canary
from canary_framework.web.fastapi import router, get, WebCanary
class DBConfig(BaseModel):
connection_string: str = "postgresql://localhost/mydb"
pool_size: int = 10
class AppConfig(BaseModel):
uvicorn_host: str = "127.0.0.1"
uvicorn_port: int = 8000
fastapi_title: str = "My API"
dbservice: DBConfig = DBConfig()
@service(name="dbservice")
class DBService:
@on_config
def setup(self) -> None:
print(f"DB ready at {self.connection_string}")
@router(prefix="/api", tags=["api"])
class APIRouter:
@get("/hello")
async def hello(self) -> dict:
return {"message": "Hello, world!"}
@module(name="AppModule", services=[APIRouter, DBService])
class AppModule:
pass
async def main() -> None:
app = WebCanary(AppModule)
await app.config(config=AppConfig())
await app.init()
await app.start()
asyncio.run(main())
Documentation
📖 Full documentation: Canary Framework Docs
中文文档: docs/zh/ · English: docs/en/
Architecture
src/canary_framework/
├── common/ # Shared types, enums, exceptions, logging
├── core/
│ ├── decorators/ # @service, @module, lifecycle hooks
│ ├── conductor/ # Canary engine (lifecycle orchestrator)
│ ├── container/ # Registry (service storage/lookup)
│ └── algorithms/ # Topological sort, DI injector, naming
└── web/
└── fastapi/ # WebCanary engine, @router, @get/@post/...
Canary.config()
├── _collect() recursively discover @service/@module
├── _validate() validate dependency integrity
├── topological_sort() Kahn topological sort
├── instantiate() create all service instances
├── _wire_entry() DI + config injection + sub-service injection
└── on_config hooks (topological order)
Canary.init()
└── per topology: on_init()
Canary.start()
└── per topology: on_start()
Canary.stop()
└── reverse order: on_end()
Community
- 💬 Discussions
- 🐛 Issues
- 📖 Docs
Contributing
See CONTRIBUTING.md.
License
Apache 2.0 · Copyright 2026 张文博 (Canary)
Project details
Release history Release notifications | RSS feed
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 canary_framework-0.3.2.tar.gz.
File metadata
- Download URL: canary_framework-0.3.2.tar.gz
- Upload date:
- Size: 74.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca21cde13f86567ecdf9e329469804646385bef666508e2fe3d51b86be0eeca9
|
|
| MD5 |
800ad5fd4909f37477c1a8222401698c
|
|
| BLAKE2b-256 |
3c814cb9b164cbc8aab402472f6b602bc96075892f3a5536f1a17d5bfbe4b69c
|
Provenance
The following attestation bundles were made for canary_framework-0.3.2.tar.gz:
Publisher:
publish.yml on HotcocoaCanary/Canary-Framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canary_framework-0.3.2.tar.gz -
Subject digest:
ca21cde13f86567ecdf9e329469804646385bef666508e2fe3d51b86be0eeca9 - Sigstore transparency entry: 1639876867
- Sigstore integration time:
-
Permalink:
HotcocoaCanary/Canary-Framework@5ab95dcf28c9b6cee7d38bb117cbd5526ef375a5 -
Branch / Tag:
refs/heads/releases/v0.3.2 - Owner: https://github.com/HotcocoaCanary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ab95dcf28c9b6cee7d38bb117cbd5526ef375a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file canary_framework-0.3.2-py3-none-any.whl.
File metadata
- Download URL: canary_framework-0.3.2-py3-none-any.whl
- Upload date:
- Size: 47.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b74b4e3c5b869ac08453105dd479174ab543243f9f6376ed7704d5d47ac81eff
|
|
| MD5 |
51bd89bd6922b6ea5321663a513ddbed
|
|
| BLAKE2b-256 |
827968f79a6d18231a1bc624e88ab1006ac61e987544f613ed58a42d08949b81
|
Provenance
The following attestation bundles were made for canary_framework-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on HotcocoaCanary/Canary-Framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canary_framework-0.3.2-py3-none-any.whl -
Subject digest:
b74b4e3c5b869ac08453105dd479174ab543243f9f6376ed7704d5d47ac81eff - Sigstore transparency entry: 1639877022
- Sigstore integration time:
-
Permalink:
HotcocoaCanary/Canary-Framework@5ab95dcf28c9b6cee7d38bb117cbd5526ef375a5 -
Branch / Tag:
refs/heads/releases/v0.3.2 - Owner: https://github.com/HotcocoaCanary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ab95dcf28c9b6cee7d38bb117cbd5526ef375a5 -
Trigger Event:
push
-
Statement type: