cosalette lets you build IoT-to-MQTT bridge daemons in Python with minimal boilerplate. You define devices (telemetry pollers or command handlers), register hardware adapters, and the framework handles MQTT wiring, structured logging, health reporting, error publishing, and graceful lifecycle management.
import cosalette
app = cosalette.App(name="sensor2mqtt", version="0.1.0")
@app.telemetry("sensor", interval=5.0)
async def sensor() -> dict[str, object]:
return {"temperature": 21.5, "humidity": 55.0}
if __name__ == "__main__":
app.run()See the full Quickstart for a complete walkthrough.
For production apps, use Router to organize devices into separate modules without
circular imports:
# sensors.py
import cosalette
router = cosalette.Router(prefix="sensors")
@router.telemetry("temperature", interval=30)
async def read_temp() -> dict[str, object]:
return {"celsius": 22.5}
# main.py
import cosalette
from sensors import router
app = cosalette.App(name="home2mqtt", version="1.0.0")
app.include_router(router)
# → publishes to: home2mqtt/sensors/temperature/stateSee Router Composition for full patterns.
cosalette supports Pydantic-validated payloads and typed returns for type-safe command handlers and telemetry, plus dependency injection for shared logic:
from typing import Annotated
from pydantic import BaseModel
import cosalette
app = cosalette.App(name="thermo2mqtt", version="1.0.0")
class SetpointCommand(BaseModel):
value: float
unit: str = "celsius"
class ThermostatState(BaseModel):
setpoint: float
unit: str
def get_device_id() -> str:
return "thermo-001"
@app.command("thermostat/set")
async def set_temp(
cmd: Annotated[SetpointCommand, cosalette.Payload()],
device_id: Annotated[str, cosalette.Depends(get_device_id)],
) -> ThermostatState:
return ThermostatState(setpoint=cmd.value, unit=cmd.unit)Inspect the contract to generate AsyncAPI docs or consumer artifacts:
cosalette manifest myapp.main:app # JSON AsyncAPI 3.0.0
cosalette manifest myapp.main:app --table # human-readable tableOr programmatically:
doc = app.asyncapi() # returns dict conforming to AsyncAPI 3.0.0See Contract-First Route Design and Schema Enforcement for full details.
- Declarative device registration — define telemetry and command devices with
@app.telemetry(),@app.command(), and@app.device()(guide) - Hexagonal architecture — protocol-based ports keep hardware adapters swappable and testable (concept)
- Lifespan + dependency injection — structured startup/teardown and type-based DI for adapters, settings, and shared state (guide)
- Command routing — use sub-topic handlers and
ctx.commands()for clean control flows (guide) - Flexible scheduling — combine fixed intervals, Quartz cron, and
ctx.sleep_until()wall-clock timing - Publish strategies — emit on change, on cadence, or with composed rules (concept)
- Health checks + auto-restart — monitor adapters and recover from wedged hardware automatically (concept)
- Persistence — store state with JSON, SQLite, or in-memory backends plus save policies (concept)
- Schema-aware integrations — validate payloads and generate consumer artifacts from AsyncAPI schemas (guide)
- AI-assisted development — optional MCP tools plus packaged instructions for Copilot and other IDE-native agents (guide)
pip install cosaletteOr with uv:
uv add cosaletteTo include the optional MCP server for IDE-native AI agent integration (VS Code Copilot, Cursor, Windsurf, Claude Code):
uv add 'cosalette[mcp]'
pip install 'cosalette[mcp]'See the MCP Server guide for setup and tool reference.
See CONTRIBUTING.md for development setup, commands, project structure, and code quality standards.
Full documentation is published at
ff-fab.github.io/cosalette. Development docs
tracking the main branch are available at
Dev Docs (latest).
| Section | What you'll find |
|---|---|
| Getting Started | Installation, quickstart tutorial |
| Concepts | Architecture, lifecycle, health checks, filters, persistence |
| How-To Guides | Telemetry, commands, adapters, lifespan DI, schema, testing, MCP |
| Reference | API docs, CLI options, payload schemas |
| ADRs | Architecture Decision Records |
MIT License. See LICENSE for details.