This is an example project demonstrating how to use Hatchet with Python.
Before running this project, make sure you have the following:
- Python 3.10 or higher installed on your machine.
- Poetry package manager installed. You can install it by running
pip install poetry
, or by following instructions in the Poetry Docs
- Create a
.env
file in the./backend
directory and set the required environment variables. This requires theHATCHET_CLIENT_TOKEN
variable created in the Getting Started README. If you would like to try the Generative AI examples in ./src/genai You will also need, aOPENAI_API_KEY
which can be created on the OpenAI Website.
If you're running Hatchet locally without TLS:
HATCHET_CLIENT_TLS_STRATEGY=none
HATCHET_CLIENT_TOKEN="<token>"
OPENAI_API_KEY="<openai-key>" # (OPTIONAL) only required to run examples in [./src/genai](./src/genai)
If you're using Hatchet Cloud:
HATCHET_CLIENT_TOKEN="<token>"
OPENAI_API_KEY="<openai-key>" # (OPTIONAL) only required to run examples in [./src/genai](./src/genai)
-
Open a terminal and navigate to the project root directory (
/simple-examples
). -
Run the following command to install the project dependencies:
poetry install
Next, start the the Hatchet worker by running the following command:
poetry run hatchet
Follow the instructions in the root project setup to launch the playground and start workflow runs.
The project contains example workflows in the ./src
directory. These workflows are registered with hatchet in ./src/main.py
which is started when running poetry run hatchet
.
The project includes a variety of basic workflows to demonstrate Hatchet's core capabilities, each showcasing different features:
- Simple Workflow: Demonstrates a straightforward process flow, showcasing the basics of setting up a workflow in Hatchet.
- Async Workflow: An example of using
async def
together withasyncio.sleep
. - Concurrency Limit Workflow: Shows how to manage concurrency limits within workflows to ensure that only a certain number of instances run simultaneously.
- Directed Acyclic Graph (DAG) Workflow: Illustrates setting up workflows with dependencies that form a Directed Acyclic Graph, demonstrating the advanced orchestration capabilities of Hatchet.
- Manual Trigger Workflow: Explains how to initiate workflows manually, offering control over workflow execution triggers.
- Timeout Workflow: Demonstrates handling timeout scenarios within workflows, ensuring that long-running or stalled processes are appropriately managed.
For more complex use cases, the project includes examples that integrate with OpenAI's API for generative tasks:
- Simple Response Generation: A single-step workflow that makes a request to OpenAI, showcasing how to incorporate AI services into Hatchet workflows.
- Basic Retrieval Augmented Generation (BasicRag): A multi-step workflow that involves loading website content with Beautiful Soup, reasoning about the information, and generating a response with OpenAI, demonstrating the potential for complex, AI-driven processes.
For a more complete example of how you might use Hatchet as part of a deployed production service, check out the FastAPI Example