Skip to main content

slimfaas-client

Durable Streams use subscribe_streams=[SubscribeStreamConfig("orders")] and client.on_stream_message(handler). A StreamMessage includes stream_name, message_id, attempt element_id and the original request. Return final status or 202, then complete through send_callback. Registration requires streams-v1; reconnect preserves progress. See Streams examples.

Python client to connect Jobs or virtual functions to SlimFaas via WebSocket. Lets any process receive async requests and publish/subscribe events without exposing an HTTP port.

The client retains active handler tasks until they finish, including while they await application work. Completed tasks are released automatically.

One outbound connection to any SlimFaas node is sufficient: sync, async and event ingress on other nodes relays to its owner; Streams consume on the connected node. Configuration must match across clients sharing a name. SDK wire messages are unchanged. See multi-node routing and failures.

PyPI PyPI Downloads Python Versions GitHub Website

Links:

Requirements

  • Python ≥ 3.10
  • UV as package manager

Installation

uv add slimfaas-client
# or from source
uv pip install -e .

Quick start

Opt into durable async failures using the existing configuration string:

import json
from slimfaas_client import SlimFaasClientConfig

config = SlimFaasClientConfig(
    function_name="billing",
    configuration=json.dumps({"DefaultAsync": {
        "HttpTimeout": 120,
        "DeadLetterQueue": {"Enabled": True, "MaxAgeSeconds": 604800, "MaxLength": 10000},
    }}),
)

The runtime validates this JSON; all clients sharing the name must match. Return the actual final status from the async handler, or 202 followed by an explicit completion callback for deferred work. Replay gets a fresh execution ID and current retries; handlers must tolerate duplicate delivery. DLQ management is private independently of function visibility. See the DLQ guide.

import asyncio
from slimfaas_client import (
    SlimFaasClient, SlimFaasClientConfig,
    SubscribeEventConfig, FunctionVisibility,
    AsyncRequest, PublishEvent,
)

async def handle_request(req: AsyncRequest) -> int:
    """Called when SlimFaas sends an async-function request.
    Return an HTTP status code (200 = success, 500 = error, 202 = long processing)."""
    print(f"{req.method} {req.path}{req.query}")
    print(f"Body: {req.body}")
    return 200

async def handle_event(evt: PublishEvent) -> None:
    """Called when SlimFaas publishes a publish-event."""
    print(f"Event '{evt.event_name}': {evt.body}")

async def main():
    config = SlimFaasClientConfig(
        function_name="my-job",
        subscribe_events=[
            SubscribeEventConfig(name="order-created"),
            SubscribeEventConfig(name="order-updated"),
        ],
        default_visibility=FunctionVisibility.PUBLIC,
        number_parallel_request=5,
    )

    async with SlimFaasClient("ws://slimfaas:5003/ws", config) as client:
        client.on_async_request(handle_request)
        client.on_publish_event(handle_event)
        await client.run_forever()

asyncio.run(main())

Full configuration

from slimfaas_client import (
    SlimFaasClientConfig, SubscribeEventConfig, PathVisibilityConfig,
    FunctionVisibility, FunctionTrust,
)

config = SlimFaasClientConfig(
    function_name="my-job",

    # SlimFaas/DependsOn
    depends_on=["other-function"],

    # SlimFaas/SubscribeEvents — each entry may override visibility individually
    subscribe_events=[
        SubscribeEventConfig(name="my-event", visibility=FunctionVisibility.PUBLIC),
        SubscribeEventConfig(name="internal-event"),  # inherits default_visibility
    ],

    # SlimFaas/DefaultVisibility
    default_visibility=FunctionVisibility.PUBLIC,  # or PRIVATE

    # SlimFaas/PathsStartWithVisibility
    paths_start_with_visibility=[
        PathVisibilityConfig(path="/admin", visibility=FunctionVisibility.PRIVATE),
    ],

    # SlimFaas/Configuration
    configuration='{"key": "value"}',

    # SlimFaas/ReplicasStartAsSoonAsOneFunctionRetrieveARequest
    replicas_start_as_soon_as_one_function_retrieve_a_request=True,

    # SlimFaas/NumberParallelRequest
    number_parallel_request=10,

    # SlimFaas/NumberParallelRequestPerPod
    number_parallel_request_per_pod=5,

    # SlimFaas/DefaultTrust
    default_trust=FunctionTrust.TRUSTED,  # or UNTRUSTED
)

Sync streaming (HTTP-over-WebSocket)

from slimfaas_client import SyncRequest

async def handle_sync(req: SyncRequest) -> None:
    body = b'{"status": "ok"}'
    await req.response.start(200, {"Content-Type": ["application/json"]})
    await req.response.write(body)
    await req.response.complete()

client.on_sync_request(handle_sync)

If the handler raises before the response starts, the client sends a 500. If it raises after the status and headers are sent, the status can no longer change, so the client cancels the stream and the caller gets a truncated response. See sync streaming.

Long-running requests (status 202)

Return 202 to acknowledge the request without completing it yet, then call send_callback when done:

async def handle_long(req: AsyncRequest) -> int:
    asyncio.create_task(process_in_background(req))
    return 202  # "I'll handle it — will call back"

async def process_in_background(req: AsyncRequest) -> None:
    await asyncio.sleep(10)
    await client.send_callback(req.element_id, 200)

Dependency injection

The handlers are plain async functions, so you can close over any dependency you resolved from your DI framework:

# Example with a database session from SQLAlchemy
from sqlalchemy.ext.asyncio import AsyncSession

async def make_handler(session: AsyncSession):
    async def handle_request(req: AsyncRequest) -> int:
        await session.execute(...)  # use the injected session
        return 200
    return handle_request

client.on_async_request(await make_handler(db_session))

Automatic reconnection

The client reconnects automatically after a disconnection. Configure the delay between attempts and the keepalive ping interval:

client = SlimFaasClient(
    "ws://...",
    config,
    reconnect_delay=10.0,
    ping_interval=30.0,  # use 0 to disable keepalive pings
)

Important rules

  1. function_name must not match an existing Kubernetes Deployment name. SlimFaas will reject the registration with a SlimFaasRegistrationError.

  2. All clients sharing the same function_name must have the exact same configuration. Mismatches are rejected on connection.

Development

uv sync --extra dev
uv run pytest

Metadata

Release files for slimfaas-client 0.88.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slimfaas-client 0.88.0
File Size Uploaded Provenance Actions
slimfaas_client-0.88.0.tar.gz 82.9 kB Without provenance Details for slimfaas_client-0.88.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for slimfaas-client 0.88.0
File Interpreter ABI Platform Actions
slimfaas_client-0.88.0-py3-none-any.whl Python 3 none any Details for slimfaas_client-0.88.0-py3-none-any.whl

Total release size: 98.0 kB

Release files / slimfaas_client-0.88.0.tar.gz

Download URL slimfaas_client-0.88.0.tar.gz
Size 82.9 kB
Tags Source
SHA-256 checksum
How to use checksums
32c8e4d7b9b502a2baf21121c5e49729a956ab3dcb1a09d2bafd131e45c9c33d
BLAKE2b-256 checksum
How to use checksums
85a90bd5efaa90af22ee8b16a82ac4bff1009ea2fd2fb3284aac8a53358806fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / slimfaas_client-0.88.0-py3-none-any.whl

Download URL slimfaas_client-0.88.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9505c07698a2d6090ca96ff84345add207d1f6c0ee145d2115ceea16977380e
BLAKE2b-256 checksum
How to use checksums
5683effa79b72970463a798993c3e3f58af8a44c29aa874c15abed79acb53431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for slimfaas-client 0.88.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.88.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page