Lightweight, efficient and developer-friendly framework for component communication
Project description
FastCC
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
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
fastcc-3.1.1.tar.gz
(12.1 kB
view details)
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
fastcc-3.1.1-py3-none-any.whl
(12.2 kB
view details)
File details
Details for the file fastcc-3.1.1.tar.gz.
File metadata
- Download URL: fastcc-3.1.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d3e88630ea1ef4a3bf13823b8cfc92b12815d1bfae9072c5f8671c294ef75c0
|
|
| MD5 |
2778a19866b9702f62817acbaad4d461
|
|
| BLAKE2b-256 |
52d0d41bc1bb9a0a56b13b6337d2e1e18dcae5ed307fb2a4ed094ac7c218f1e2
|
File details
Details for the file fastcc-3.1.1-py3-none-any.whl.
File metadata
- Download URL: fastcc-3.1.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
060f778d0e97864486c7930a833ea6f9f22dac43f8aec74e810cc4fa2643e2d2
|
|
| MD5 |
69f9ad104f9e23275145cf44dd6940e1
|
|
| BLAKE2b-256 |
024d1e46ef5071f4214eb22c250da833eeab43c3770966970ac7488bdac11b86
|