Skip to main content

an opinionated Python framework for building IoT-to-MQTT bridge applications

Project description

cosalette

cosalette — An opinionated Python framework for IoT-to-MQTT bridges

What is cosalette?

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.

Quick Example

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.

Router Composition (Multi-Module Apps)

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/state

See Router Composition for full patterns.

Typed Contracts & Schema Inspection

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 table

Or programmatically:

doc = app.asyncapi()  # returns dict conforming to AsyncAPI 3.0.0

See Contract-First Route Design and Schema Enforcement for full details.

Key Features

  • 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)

Installation

pip install cosalette

Or with uv:

uv add cosalette

To 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.

Contributing

See CONTRIBUTING.md for development setup, commands, project structure, and code quality standards.

Documentation

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

License

MIT License. See LICENSE for details.

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

cosalette-0.4.4.tar.gz (349.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cosalette-0.4.4-cp314-abi3-win_amd64.whl (558.3 kB view details)

Uploaded CPython 3.14+Windows x86-64

cosalette-0.4.4-cp314-abi3-musllinux_1_2_x86_64.whl (903.2 kB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ x86-64

cosalette-0.4.4-cp314-abi3-musllinux_1_2_aarch64.whl (872.1 kB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

cosalette-0.4.4-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (700.2 kB view details)

Uploaded CPython 3.14+manylinux: glibc 2.17+ x86-64

cosalette-0.4.4-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (703.7 kB view details)

Uploaded CPython 3.14+manylinux: glibc 2.17+ ARMv7l

cosalette-0.4.4-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (696.5 kB view details)

Uploaded CPython 3.14+manylinux: glibc 2.17+ ARM64

cosalette-0.4.4-cp314-abi3-macosx_11_0_arm64.whl (664.0 kB view details)

Uploaded CPython 3.14+macOS 11.0+ ARM64

cosalette-0.4.4-cp314-abi3-macosx_10_12_x86_64.whl (666.4 kB view details)

Uploaded CPython 3.14+macOS 10.12+ x86-64

File details

Details for the file cosalette-0.4.4.tar.gz.

File metadata

  • Download URL: cosalette-0.4.4.tar.gz
  • Upload date:
  • Size: 349.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for cosalette-0.4.4.tar.gz
Algorithm Hash digest
SHA256 e5a2710157abc9470b9bc483c139b1abc085a68d3e9e4a583f829276de32bafb
MD5 97e579ae888ef8503e4901f45f6f26d3
BLAKE2b-256 c52c7f87275e75067ccbf4cdfeb31d04d7746be758dec19c1b048e9426d6d52f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4.tar.gz:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-win_amd64.whl.

File metadata

  • Download URL: cosalette-0.4.4-cp314-abi3-win_amd64.whl
  • Upload date:
  • Size: 558.3 kB
  • Tags: CPython 3.14+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1258aaff602bf57a5da2b664c1483f14b0848df728956a4feeb09c0c2de8b0fa
MD5 a9161b307f316b7d95c28b5f7d41de05
BLAKE2b-256 b8ea7bbdbc59ea2c2e9cb38623781ba206e0e9d3103f16a88292508f95f9f7d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-win_amd64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b072bec438238838cae25edabe52846de651773e8028e6265a28a37d3ce6081f
MD5 1042b3bf26fc6da3a305ddf48831fc8c
BLAKE2b-256 71c37b395180e8c77d4c5dcba973872b0b5e4bb7050ffeccb935416185544c19

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-musllinux_1_2_x86_64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cdf10e7a3aaf1a775cc65a72ca33ed4b73b81e9b63182843a8d2708002f19f86
MD5 e2021fefdb9db981494467769a0612b1
BLAKE2b-256 b0961a16cbd2816efe85e5428fd2f0e1df8e28d34ea3a16ff5f5628ac26a6a38

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-musllinux_1_2_aarch64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ee756c74e8b45cb591cf4a119a97d3c7932166607f8e8162316b2bb2c0abced
MD5 07a8133a95c4b837e8c9efca5e3d88b2
BLAKE2b-256 c66020f4f6815aabac1c5cf0516d912a996944ddb6e9c2ff5768c6a1e5562539

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0f4ddc43485e87faefdc833de577120f46c892efb3a2a4596a863d0288454af5
MD5 821245e78c7542ea62c51f563b053b17
BLAKE2b-256 726ca55551138a810ddc94314c2a5fa20eec81557cca6f3584827ac79b143f30

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 95474ff9c19c39b76b405354832f380e2415bb8147015c886019d34786995a8a
MD5 2f404213c823c8581c5154a2b80ed9fd
BLAKE2b-256 4d35a519e4e2e50033fad885cf34df0513f6738aaf694b65fc6f905ad367cdde

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b54b5000d71da6d0f57ebf2db6760e55f99e359115e8e0f27a547665d30febce
MD5 678e5171a9e7f0d1d4cd0451c3dc8cc3
BLAKE2b-256 b4108e8bb83081b4049807c9c18b903c16d0b48d6acd9f0994fa20d18ef45c4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-macosx_11_0_arm64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cosalette-0.4.4-cp314-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.4-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b5bf34caa5b345842edd2ec1fcbb343e6b10d7d840a091a4233e986970704f01
MD5 a5551274deca46b845f49b8935f5437b
BLAKE2b-256 cc7854068f70c55276abb2eb0b8912b9a47e858e5b7af37625fc9fda7da8e09d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.4-cp314-abi3-macosx_10_12_x86_64.whl:

Publisher: release-please.yml on ff-fab/cosalette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page