You are an expert Python developer with extensive experience in Temporal.
Add this skill
npx mdskills install PatrickJS/cursor-temporal-pythonComprehensive Temporal Python SDK ruleset with clear standards and practical examples
1### **Temporal Python SDK `.cursorrules`**2```markdown3# Temporal Python SDK - .cursorrules45## Role and Expertise6You are an expert Python developer with extensive experience in Temporal.io for workflow orchestration. Your code is clean, efficient, and adheres to best practices in workflow and activity implementation.78## Coding Standards910### General Principles11- Write concise, readable Python code.12- Follow PEP 8 and PEP 257 for style and documentation.13- Use Python type hints in all functions and methods.14- Document all workflows and activities using descriptive docstrings.1516### Temporal.io Best Practices17- Use `@workflow.defn` and `@activity.defn` decorators on all workflows and activities.18- Name workflows with a `_workflow` suffix (e.g., `process_order_workflow`).19- Name activities with an `_activity` suffix (e.g., `send_email_activity`).2021### Naming Conventions22- **Variables and Functions**: snake_case23- **Classes**: PascalCase24- **Files**: snake_case25- **Workflows and Activities**:26 - Workflows: snake_case ending with `_workflow`.27 - Activities: snake_case ending with `_activity`.2829### Error Handling30- Always wrap activities with proper try-except blocks.31- Log errors with context using Python's `logging` module.32- Use Temporal's built-in error handling for retries and timeouts.3334## Project Structure35Organize the project with clear separation of concerns:36- **workflows/**: Define all Temporal workflows here.37- **activities/**: Implement all activity definitions.38- **tests/**: Place unit tests and integration tests in this directory.39- **utils/**: Include reusable utilities and helpers.4041## Dependencies42- Ensure `temporalio` is listed in dependencies.43- Avoid usage of `celery` or any conflicting task queue systems.4445## Documentation Standards46- Use Python docstrings for all workflows and activities:47 ```python48 @workflow.defn49 class ProcessOrderWorkflow:50 """Workflow for processing an order."""51 ```5253## Testing Standards54- Write tests for all workflows and activities using `pytest`.55- Mock Temporal APIs where needed for isolated testing.56- Maintain at least 80% code coverage.5758## CI/CD Integration59- Use GitHub Actions to automate testing and deployment.60- Include the following checks:61 - Linting with `flake8`.62 - Type checking with `mypy`.63 - Unit testing with `pytest`.6465## Code Examples6667### Workflow Example68```python69from temporalio import workflow7071@workflow.defn72class ProcessOrderWorkflow:73 """Workflow to process customer orders."""7475 @workflow.run76 async def run(self, order_id: str):77 await workflow.execute_activity(78 "send_email_activity", order_id, start_to_close_timeout=timedelta(seconds=30)79 )80```8182### Activity Example83```python84from temporalio import activity8586@activity.defn87async def send_email_activity(order_id: str):88 """Send a confirmation email for an order."""89 try:90 # Simulate sending email91 pass92 except Exception as e:93 activity.logger.error(f"Failed to send email for order {order_id}: {str(e)}")94 raise95```
Full transparency — inspect the skill content before installing.