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.3.0.tar.gz (5.9 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.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for temporaliox-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d62ee12bbbed6fe9bcd82d3f4ff562b6998787815cf24c8f0c22b8ddf6c909fd
MD5 f5e4fd33ebd8336ec5015e15e87fa12d
BLAKE2b-256 7d0cbdc9ff1530b62e6aa8aa6d7183f010da3889ea10e02d98a249e3ff6146c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporaliox-0.3.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.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for temporaliox-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14ad808c4ae7ca74e312cba1003def24f6cae1af73f4669b8f64733776c70dbb
MD5 b03f0e54b0206b379710c332ed9e53ca
BLAKE2b-256 0ea67347ee74c1ab526bd5c52ebe77877cff13796acc06f5b1c594257479293a

See more details on using hashes here.

Provenance

The following attestation bundles were made for temporaliox-0.3.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