Python client SDK for the Fila message broker
Project description
fila-python
Python client SDK for the Fila message broker.
Installation
pip install fila-python
Usage (Sync)
from fila import Client
client = Client("localhost:5555")
# Enqueue a message.
msg_id = client.enqueue("my-queue", {"tenant": "acme"}, b"hello world")
print(f"Enqueued: {msg_id}")
# Consume messages.
for msg in client.consume("my-queue"):
print(f"Received: {msg.id} (attempt {msg.attempt_count})")
# Acknowledge successful processing.
client.ack("my-queue", msg.id)
client.close()
Usage (Async)
import asyncio
from fila import AsyncClient
async def main():
async with AsyncClient("localhost:5555") as client:
msg_id = await client.enqueue("my-queue", {"tenant": "acme"}, b"hello")
async for msg in await client.consume("my-queue"):
print(f"Received: {msg.id}")
await client.ack("my-queue", msg.id)
asyncio.run(main())
TLS
For servers using certificates from a public CA (e.g., Let's Encrypt), enable TLS with the system trust store:
from fila import Client
# TLS using OS system trust store.
client = Client("localhost:5555", tls=True)
For servers using a private CA, provide the CA certificate explicitly:
from fila import Client
# Read certificates.
with open("ca.pem", "rb") as f:
ca_cert = f.read()
with open("client.pem", "rb") as f:
client_cert = f.read()
with open("client-key.pem", "rb") as f:
client_key = f.read()
# TLS with custom CA (server verification).
client = Client("localhost:5555", ca_cert=ca_cert)
# Mutual TLS (client + server verification).
client = Client(
"localhost:5555",
ca_cert=ca_cert,
client_cert=client_cert,
client_key=client_key,
)
Note: ca_cert implies tls=True -- you don't need to pass both.
API Key Authentication
When the server has API key auth enabled, pass the key to the client:
from fila import Client
client = Client("localhost:5555", api_key="fila_your_api_key_here")
# Combined with TLS:
client = Client(
"localhost:5555",
ca_cert=ca_cert,
api_key="fila_your_api_key_here",
)
The API key is sent as authorization: Bearer <key> metadata on every RPC.
API
Client(addr, *, tls=False, ca_cert=None, client_cert=None, client_key=None, api_key=None) / AsyncClient(...)
Connect to a Fila broker. Both support context manager protocol.
client.enqueue(queue, headers, payload) -> str
Enqueue a message. Returns the broker-assigned message ID.
client.consume(queue) -> Iterator[ConsumeMessage]
Open a streaming consumer. Returns an iterator (sync) or async iterator (async) that yields messages as they become available.
client.ack(queue, msg_id)
Acknowledge a successfully processed message. The message is permanently removed.
client.nack(queue, msg_id, error)
Negatively acknowledge a failed message. The message is requeued or routed to the dead-letter queue based on the queue's configuration.
Error Handling
Per-operation exception classes:
from fila import QueueNotFoundError, MessageNotFoundError
try:
client.enqueue("missing-queue", None, b"test")
except QueueNotFoundError:
print("Queue does not exist")
try:
client.ack("my-queue", "missing-id")
except MessageNotFoundError:
print("Message does not exist")
License
AGPLv3
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
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
File details
Details for the file fila_python-0.2.0.tar.gz.
File metadata
- Download URL: fila_python-0.2.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7fead49ede2714cf50e8276ab1a02dfceb5041a1e792ec0e707b2d7da61a085
|
|
| MD5 |
9de87e7cb1baece47c832f0655e1382d
|
|
| BLAKE2b-256 |
3d6b5a806c6524fa1c16660653ed57a170b33060b63ad1dbacde73d1db429f34
|
Provenance
The following attestation bundles were made for fila_python-0.2.0.tar.gz:
Publisher:
publish.yml on faiscadev/fila-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fila_python-0.2.0.tar.gz -
Subject digest:
e7fead49ede2714cf50e8276ab1a02dfceb5041a1e792ec0e707b2d7da61a085 - Sigstore transparency entry: 1169143950
- Sigstore integration time:
-
Permalink:
faiscadev/fila-python@872b5926aa99f34e955ac2b53ae6bb6a650f8155 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/faiscadev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@872b5926aa99f34e955ac2b53ae6bb6a650f8155 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fila_python-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fila_python-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7563856f48c21721f8cfc089d1228323ca32e3aba420884690db58a959e3c255
|
|
| MD5 |
aba461dcd5ccf48bb7381582a10d05e6
|
|
| BLAKE2b-256 |
0685025a9610cc86a971c31138bfb5fbbbefa5fcaffe12dfd239349e005cb7a4
|
Provenance
The following attestation bundles were made for fila_python-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on faiscadev/fila-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fila_python-0.2.0-py3-none-any.whl -
Subject digest:
7563856f48c21721f8cfc089d1228323ca32e3aba420884690db58a959e3c255 - Sigstore transparency entry: 1169144028
- Sigstore integration time:
-
Permalink:
faiscadev/fila-python@872b5926aa99f34e955ac2b53ae6bb6a650f8155 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/faiscadev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@872b5926aa99f34e955ac2b53ae6bb6a650f8155 -
Trigger Event:
push
-
Statement type: