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
ValueErrorif 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.defndecorator - 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
@decl()creates anActivityDeclarationthat holds the activity configuration and registers it as undefined@ActivityDeclaration.defndecorates the implementation, registers it with Temporal, and moves it to the implemented registry- When called in a workflow, the activity uses
workflow.execute_activityorworkflow.start_activitywith the configured options 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d62ee12bbbed6fe9bcd82d3f4ff562b6998787815cf24c8f0c22b8ddf6c909fd
|
|
| MD5 |
f5e4fd33ebd8336ec5015e15e87fa12d
|
|
| BLAKE2b-256 |
7d0cbdc9ff1530b62e6aa8aa6d7183f010da3889ea10e02d98a249e3ff6146c9
|
Provenance
The following attestation bundles were made for temporaliox-0.3.0.tar.gz:
Publisher:
publish.yml on ikseek/temporaliox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
temporaliox-0.3.0.tar.gz -
Subject digest:
d62ee12bbbed6fe9bcd82d3f4ff562b6998787815cf24c8f0c22b8ddf6c909fd - Sigstore transparency entry: 706747834
- Sigstore integration time:
-
Permalink:
ikseek/temporaliox@e55898066f65c20c7e1a9c31148bb10a7c1661b1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ikseek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e55898066f65c20c7e1a9c31148bb10a7c1661b1 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14ad808c4ae7ca74e312cba1003def24f6cae1af73f4669b8f64733776c70dbb
|
|
| MD5 |
b03f0e54b0206b379710c332ed9e53ca
|
|
| BLAKE2b-256 |
0ea67347ee74c1ab526bd5c52ebe77877cff13796acc06f5b1c594257479293a
|
Provenance
The following attestation bundles were made for temporaliox-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on ikseek/temporaliox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
temporaliox-0.3.0-py3-none-any.whl -
Subject digest:
14ad808c4ae7ca74e312cba1003def24f6cae1af73f4669b8f64733776c70dbb - Sigstore transparency entry: 706747843
- Sigstore integration time:
-
Permalink:
ikseek/temporaliox@e55898066f65c20c7e1a9c31148bb10a7c1661b1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/ikseek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e55898066f65c20c7e1a9c31148bb10a7c1661b1 -
Trigger Event:
release
-
Statement type: