Skip to main content

Lightweight, efficient and developer-friendly framework for component communication

Project description

drawing

FastCC

Ruff Mypy Gitmoji

Framework for component communication with MQTT and Protocol Buffers :boom:.

  • Lightweight :zap:
  • Efficient :rocket:
  • Developer-friendly :technologist:

This framework is built on top of empicano's aiomqtt.

Example

# app.py
from __future__ import annotations

import asyncio
import contextlib
import logging
import os
import sys
import typing

import fastcc

router = fastcc.Router()


@router.route("greet")
async def greet(name: str, *, database: dict[str, typing.Any]) -> str:
    """Greet a user.

    Parameters
    ----------
    name
        The name of the user.
        Autofilled by fastcc.
    database
        The database.
        Autofilled by fastcc.

    Returns
    -------
    str
        The greeting message.
    """
    # ... do some async work
    await asyncio.sleep(0.1)

    if name in database:
        return f"Hello, {name}! Welcome back!"
    return f"Hello, {name}!"


async def main() -> None:
    """Run the app."""
    logging.basicConfig(level=logging.INFO)

    database: dict[str, typing.Any] = {}
    app = fastcc.FastCC("localhost")
    app.add_router(router)
    app.add_injector(database=database)

    await app.run()


# https://github.com/empicano/aiomqtt?tab=readme-ov-file#note-for-windows-users
if sys.platform.lower() == "win32" or os.name.lower() == "nt":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

with contextlib.suppress(KeyboardInterrupt):
    asyncio.run(main())
# client.py
from __future__ import annotations

import asyncio
import contextlib
import logging
import os
import sys

import fastcc

_logger = logging.getLogger(__name__)


async def main() -> None:
    """Run the app."""
    logging.basicConfig(level=logging.INFO)

    async with fastcc.Client("localhost") as client:
        response = await client.request("greet", "Justin", response_type=str)
        _logger.info("response: %r", response)


# https://github.com/empicano/aiomqtt?tab=readme-ov-file#note-for-windows-users
if sys.platform.lower() == "win32" or os.name.lower() == "nt":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

with contextlib.suppress(KeyboardInterrupt):
    asyncio.run(main())

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

fastcc-3.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

fastcc-3.0.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file fastcc-3.0.0.tar.gz.

File metadata

  • Download URL: fastcc-3.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for fastcc-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c1d39eb3605052fa3c57d42c788a0e7081d9536c32ebfdf58171310ce1ffc287
MD5 f01bc2f05f7419c4e3e2227114cfbf36
BLAKE2b-256 1db2ec496e39410098f005481acb2fed803fdd024d2e086c26090015ccc4fc52

See more details on using hashes here.

File details

Details for the file fastcc-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: fastcc-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for fastcc-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b48a05b7bca9becaeb57287691a7388bb6c3bfe203726c39b01000b0bdf3a07
MD5 b36f4339c2e08ae22c511426e67b5b15
BLAKE2b-256 2c287bb1bbe8bbcef22a88ace3ce91ec636eb05091754d79224740ea96afeb0f

See more details on using hashes here.

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