Python SDK for Perceptic Workflow definitions - cross-language Temporal workflow types
Project description
Perceptic Workflow SDK
Python SDK for Perceptic Workflow definitions. This package provides cross-language Temporal workflow types that are compatible with the Java workflow definitions in perceptic-core-client.
Installation
uv add perceptic-workflow-sdk
Usage
Runtime Input Contract
Workflows started through Perceptic Core receive plain JSON input data.
- The first
@workflow.runargument should be a JSON-compatible structure (dict[str, Any]by default). - Perceptic Core does not wrap inputs in an SDK envelope type.
- Consumers are responsible for interpreting and validating the JSON shape they expect.
Workflow Events
from perceptic_workflow import (
WorkflowEvent,
InfoEvent,
CheckpointEvent,
UserInputEvent,
UserInputRequestEvent,
WorkflowCheckpointStatus,
)
# Create events
info_event = InfoEvent(
event_id=1,
type="progress",
payload={"step": "processing"},
timestamp=datetime.now()
)
Implementing Workflows
The SDK provides a mixin class for implementing Perceptic-compatible workflows:
from typing import Any
from pydantic import BaseModel
from temporalio import workflow
from perceptic_workflow import PercepticWorkflow, WorkflowEvent
class ResearchInput(BaseModel):
query: str
context: str
@workflow.defn
class MyWorkflow(PercepticWorkflow):
def __init__(self):
self._events: list[WorkflowEvent] = []
self._paused = False
@workflow.run
async def run(self, inputs: dict[str, Any]) -> dict:
request = ResearchInput.model_validate(inputs)
return {
"query": request.query,
"context": request.context,
}
@workflow.query(name=PercepticWorkflow.QUERY_GET_STATUS)
def get_status(self) -> WorkflowStatus:
return WorkflowStatus(status="running", description="Waiting for input" if self._paused else "Running")
@workflow.query(name=PercepticWorkflow.QUERY_GET_EVENTS)
def get_events(self, after_event_id: int | None = None) -> dict[str, Any]:
if after_event_id is None:
return {"events": self._events}
return {"events": [e for e in self._events if e["eventId"] > after_event_id]}
Decorator Validation
PercepticWorkflow no longer performs runtime validation of Temporal handler
decorators during class creation. This avoids import-time failures for abstract
workflow bases and mixin-based inheritance patterns.
Handler contract enforcement is expected to happen through linting and type-check tooling in your development pipeline:
uv run ty check
uv run workflow-typecheck
workflow-typecheck implementation notes
workflow-typecheck is implemented by
src/perceptic_workflow/_checks/workflow_decorator_check.py and performs a static
AST scan of Python classes that inherit from PercepticWorkflow (or from a
class that already does). For the known handler methods, it enforces:
- the method has a Temporal handler decorator (
@workflow.queryor@workflow.update) - the decorator kind matches the expected contract
- the
name=argument matches thePercepticWorkflowhandler constant
Current diagnostics:
PWF001: expected Temporal decorator is missingPWF002: wrong decorator kind (queryvsupdate)PWF003: wrong or missing handlername=...
How to extend the check:
- Add or update required handlers in
REQUIRED_HANDLERSwhen a new Perceptic handler method is added or an existing one changes. - Add base class names to
MIXIN_COMPATIBLE_BASESif additional workflow base classes should be recognized as Perceptic-compatible roots. - Extend
_extract_name_kwarg/_is_workflow_decorator_callif we support additional decorator call shapes or name expressions.
When this check must be updated:
- A
PercepticWorkflowhandler method is renamed, added, removed, or changes from query to update (or vice versa). - Any
PercepticWorkflow.<HANDLER_CONSTANT>used in handler decorators is renamed or replaced. - We introduce a new inheritance pattern for workflow mixins or a new canonical workflow base class.
- We change how Temporal decorators are authored (for example, different
decorator access paths or non-current
name=expression style).
How to edit safely:
- Update the contract mappings first (
REQUIRED_HANDLERS,MIXIN_COMPATIBLE_BASES). - Keep diagnostics specific and actionable (
PWF001-PWF003style). - Add or update tests in
tests/test_workflow_typecheck_regression.pyfor the new/changed behavior. - Validate with:
uv run workflow-typecheckuv run pytest tests/test_workflow_typecheck_regression.pyuv run ty check
Troubleshooting
ValidationErrorduring workflow activation usually means your@workflow.runsignature expects the wrong input shape.- Use a JSON-compatible first workflow argument (for example
dict[str, Any]), then validate/coerce into your domain model insiderun. - For run-start requests, send
inputsonly; Perceptic Core forwards that JSON payload directly.
Compatibility
This package is designed to be compatible with:
- perceptic-core-client (Java)
- perceptic-core-workflow-runtime (Java)
The workflow definitions and event types are generated from the same JSON Schema sources to ensure cross-language compatibility.
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 perceptic_workflow_sdk-0.53.1.tar.gz.
File metadata
- Download URL: perceptic_workflow_sdk-0.53.1.tar.gz
- Upload date:
- Size: 6.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 |
925cf7991a42513ee680b51c4ef2832508be9c0ec32bc0a84895ee2c128d1de8
|
|
| MD5 |
8b53abc2e6876c19d9109e7bc147139d
|
|
| BLAKE2b-256 |
932b78f2fa6445ef5eb6e74489be43c63c1f4019bb9b196481072390263254f0
|
Provenance
The following attestation bundles were made for perceptic_workflow_sdk-0.53.1.tar.gz:
Publisher:
publish-python.yml on perceptic/perceptic-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perceptic_workflow_sdk-0.53.1.tar.gz -
Subject digest:
925cf7991a42513ee680b51c4ef2832508be9c0ec32bc0a84895ee2c128d1de8 - Sigstore transparency entry: 1137306822
- Sigstore integration time:
-
Permalink:
perceptic/perceptic-core@0a359de4fdc9b560ec41e4d6226a45355f356d95 -
Branch / Tag:
refs/tags/0.53.1 - Owner: https://github.com/perceptic
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@0a359de4fdc9b560ec41e4d6226a45355f356d95 -
Trigger Event:
push
-
Statement type:
File details
Details for the file perceptic_workflow_sdk-0.53.1-py3-none-any.whl.
File metadata
- Download URL: perceptic_workflow_sdk-0.53.1-py3-none-any.whl
- Upload date:
- Size: 10.8 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 |
acdcf872f974275f93fd2e317ea030ec9d643e296378cacaa495c975b227bf9f
|
|
| MD5 |
ca94542a946d92266ebd74f8a23c9274
|
|
| BLAKE2b-256 |
04e02a8c2929cb4068597cc9a7dc0b17f5a9ce410d0fa2e1a2d0eb7d62fa64b0
|
Provenance
The following attestation bundles were made for perceptic_workflow_sdk-0.53.1-py3-none-any.whl:
Publisher:
publish-python.yml on perceptic/perceptic-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
perceptic_workflow_sdk-0.53.1-py3-none-any.whl -
Subject digest:
acdcf872f974275f93fd2e317ea030ec9d643e296378cacaa495c975b227bf9f - Sigstore transparency entry: 1137306888
- Sigstore integration time:
-
Permalink:
perceptic/perceptic-core@0a359de4fdc9b560ec41e4d6226a45355f356d95 -
Branch / Tag:
refs/tags/0.53.1 - Owner: https://github.com/perceptic
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@0a359de4fdc9b560ec41e4d6226a45355f356d95 -
Trigger Event:
push
-
Statement type: