Skip to main content

A helper library for Temporal.io that enables separation of activity declarations from implementations

Project description

TemporalioX

A helper library for Temporal.io that enables separation of activity declarations from their implementations.

Installation

pip install temporaliox

Usage

1. Declare Activities

In your activities.py file, declare activities with their Temporal configuration:

from temporaliox.activity import decl
from datetime import timedelta

@decl(task_queue="playwright", start_to_close_timeout=timedelta(seconds=60))
def generate_report(user_name: str, action: str) -> str:
    pass

2. Define Activity Implementations

In your activities_def.py file, provide the actual implementations:

from .activities import generate_report

@generate_report.defn
def generate_report_def(user_name: str, action: str) -> str:
    return f"{action}, {user_name}!"

3. Use Activities in Workflows

In your workflows.py file, call activities as normal async functions:

from temporalio import workflow
from .activities import generate_report

@workflow.defn()
class GenerateReport:
    @workflow.run
    async def run(self):
        # This will call temporalio.workflow.execute_activity under the hood
        report = await generate_report("Alice", "Hello")
        # report will be "Hello, Alice!"
        return report

Starting Activities

You can also start activities asynchronously using the .start() method:

# Start activity and get handle
handle = generate_report.start("Bob", "Goodbye")
# Wait for result later
result = await handle

4. Set Up Workers

Use activities_for_queue() to automatically collect all implemented activities for a specific task queue:

from temporalio.worker import Worker
from temporaliox.activity import activities_for_queue

async def main():
    worker = Worker(
        client,
        task_queue="playwright",
        workflows=[GenerateReport],
        activities=activities_for_queue("playwright"),  # Automatically gets all activities for this queue
    )
    await worker.run()

The activities_for_queue() function will:

  • Return all implemented activities for the specified queue
  • Raise a ValueError if any declared activities are missing implementations
  • Return an empty list if no activities exist for the queue

Features

  • Separation of Concerns: Declare activity signatures and Temporal configuration separately from implementations
  • Type Safety: Full type hints support for better IDE experience
  • Automatic Registration: Activities are automatically registered with Temporal using the @ActivityDeclaration.defn decorator
  • Flexible Execution: Support for both await (execute_activity) and .start() (start_activity) patterns
  • Queue-based Organization: Activities are organized by task queue for easy worker setup

How It Works

  1. @decl() creates an ActivityDeclaration that holds the activity configuration and registers it as undefined
  2. @ActivityDeclaration.defn decorates the implementation, registers it with Temporal, and moves it to the implemented registry
  3. When called in a workflow, the activity uses workflow.execute_activity or workflow.start_activity with the configured options
  4. activities_for_queue() collects all implemented activities for a queue, ensuring no undefined activities remain

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Start Temporal server (required for integration tests)
temporal server start-dev

# Run tests
pytest

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

temporaliox-0.4.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

temporaliox-0.4.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file temporaliox-0.4.0.tar.gz.

File metadata

  • Download URL: temporaliox-0.4.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for temporaliox-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7e2aa5161914af0be2a7d66611b6a19d3e1ac45d1d9809de6958f7d4a7386551
MD5 8eff464728c9afdffd7772cf6537e096
BLAKE2b-256 82755ab6ee6087fa94490675d29b723cc55700eb4fb9a9c6524dd8c41f4f6429

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporaliox-0.4.0.tar.gz:

Publisher: publish.yml on ikseek/temporaliox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file temporaliox-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: temporaliox-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for temporaliox-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19193501f1bcb8ff1c240e70ece0500b9b6310afd931c62da34febec799d8274
MD5 8088822e6898b48db538c008458479ea
BLAKE2b-256 6371056defd9d8bea4af78f2d1bec6460c4b7327a3c44ccdb278e0cb58745abc

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporaliox-0.4.0-py3-none-any.whl:

Publisher: publish.yml on ikseek/temporaliox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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