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.2.tar.gz (342.8 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.2-cp314-abi3-win_amd64.whl (551.3 kB view details)

Uploaded CPython 3.14+Windows x86-64

cosalette-0.4.2-cp314-abi3-musllinux_1_2_x86_64.whl (896.3 kB view details)

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

cosalette-0.4.2-cp314-abi3-musllinux_1_2_aarch64.whl (865.2 kB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

cosalette-0.4.2-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.2 kB view details)

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

cosalette-0.4.2-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (696.7 kB view details)

Uploaded CPython 3.14+manylinux: glibc 2.17+ ARMv7l

cosalette-0.4.2-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (689.5 kB view details)

Uploaded CPython 3.14+manylinux: glibc 2.17+ ARM64

cosalette-0.4.2-cp314-abi3-macosx_11_0_arm64.whl (657.0 kB view details)

Uploaded CPython 3.14+macOS 11.0+ ARM64

cosalette-0.4.2-cp314-abi3-macosx_10_12_x86_64.whl (659.4 kB view details)

Uploaded CPython 3.14+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: cosalette-0.4.2.tar.gz
  • Upload date:
  • Size: 342.8 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.2.tar.gz
Algorithm Hash digest
SHA256 10f3270ea88bdfb7f8c1f154887300cc48d18ee7ddf689495e763f980dba23da
MD5 c9163a9b210a83b011218539ff2b1948
BLAKE2b-256 1646632687703d17d53a08aaa6d15740fdceafd5fe8aec9e5e1e6df268e827d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2.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.2-cp314-abi3-win_amd64.whl.

File metadata

  • Download URL: cosalette-0.4.2-cp314-abi3-win_amd64.whl
  • Upload date:
  • Size: 551.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.2-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3bde6e46cc7bd242a876bceb36bdf3f88ebf747dc17aebd9eab3bcf0f3220e3f
MD5 775db1bd0e216d4489c5e7e2b6d15794
BLAKE2b-256 21c8cc4e1769bc43f0bb1766e4b0cf23c824a2b64bbfc84f20ca5f41d9cda462

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ce88f84c47c70d6433962f2631fc76615004adaf1ec77ac180d38a4e58bd6fca
MD5 97856595a7a55776a5b8fb918fa5d04a
BLAKE2b-256 67bf288985359d63cff9f39ce8bff956d04c373376fcf745b4e1f683b0414fd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 eedf80fffe65d02a9efb97f115e5121f60e6c9f8f6f5bafa73667b4da264b19b
MD5 659e5c284eea3353622141b5a497f6e3
BLAKE2b-256 a26193e492ea2ad9ed61992d6880a1dbfe5988d24238aa0617b00c719c5d25a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbda00efec9dbb099a84ae7a28c5ed2dc5a31b49998a4ba4995d63a89ca93e7c
MD5 0f4184e6475de4fb7cb69019313c7b1d
BLAKE2b-256 837ac0b568079e89f258a1eaf8ae88a21ace7ccb581c1acd244bffa003d83b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0f2740684fb8041bddb02847d5e448b00008db9930a0742b682353d391f12ef9
MD5 224b8b83513c193e4f396ccc037f8476
BLAKE2b-256 5848df295150050744ac7e464fbb4764c993acdedf3520d3c8620c1d95923895

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c16df64ee4d870bffba964fe2ae9746c8d56914fbfd5a65fca70c00c7827b91c
MD5 4d26ebfb837721fcd5d2fc7f61a76aa2
BLAKE2b-256 b9d0f312f7936dce16619e59e0afbb66ddb09277e054d1ee4ee2f12411975623

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 78f2dfc7114e9adc7232874622b94f845ce5e415e3c8f692d8485671db6ed9a5
MD5 3c1ca748cd18845e7475a63498dc4cf7
BLAKE2b-256 f4232df191ae4fb3982cda92617387426db0b6129f95f0d48538d2e04183ad98

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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.2-cp314-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosalette-0.4.2-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7e55bd2e6ad9767777fc96d59288af699e1d3385c198be3e0bbfe4c1265a31fc
MD5 767a9a9f5a4769ffd5d439a87ce32c34
BLAKE2b-256 366e61b8e46beaba5c4d86bc1515885e1fdbaefa827ce626d7fdf9020d69804e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosalette-0.4.2-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