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 fastcc
router = fastcc.Router()
@router.route("greet")
async def greet(name: str, *, database: dict[str, int]) -> 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)
database[name] += 1
occurrence = database[name]
return f"Hello, {name}! Saw you {occurrence} times!"
async def main() -> None:
"""Run the app."""
logging.basicConfig(level=logging.INFO)
database: dict[str, int] = {"Alice": 0, "Bob": 0}
app = fastcc.FastCC("localhost")
app.add_router(router)
app.add_injector(database=database)
app.add_exception_handler(
KeyError,
lambda e: fastcc.MQTTError(repr(e), 404),
)
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:
try:
response = await client.request(
"greet",
"Charlie",
response_type=str,
)
except fastcc.MQTTError as e:
details = f"An error occurred on the server: {e.message}"
_logger.error(details)
response = await client.request("greet", "Alice", 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-4.0.2.tar.gz
(14.3 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-4.0.2-py3-none-any.whl
(15.3 kB
view details)
File details
Details for the file fastcc-4.0.2.tar.gz.
File metadata
- Download URL: fastcc-4.0.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4129160cdc7790b2cd3f57d53737fb4343792c4d99ab28680a25986dcfd2e4aa
|
|
| MD5 |
3b5dff85677015c729205f273a3cf155
|
|
| BLAKE2b-256 |
470e9601fc95461b96e777c7c0c9e7af9047518e1ddfe29be6c38bb3774a1355
|
File details
Details for the file fastcc-4.0.2-py3-none-any.whl.
File metadata
- Download URL: fastcc-4.0.2-py3-none-any.whl
- Upload date:
- Size: 15.3 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 |
d2691cdbd182db5fdf1656fbc6d5d84c837f7fadd6c64793382b161b04fe337e
|
|
| MD5 |
dc63908893dbcb998fdc2cdc2b9621ee
|
|
| BLAKE2b-256 |
81271d61be4781975610c64f987e1429c7b4eda8a971436706a08477ff4e4c19
|