mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-05-25 04:48:44 -05:00
Fe overhaul docs (#1640)
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
certs/
|
||||
|
||||
# Environments
|
||||
.env
|
||||
env/
|
||||
venv/
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
.Python
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Distribution / packaging
|
||||
dist/
|
||||
build/
|
||||
*.egg-info/
|
||||
*.egg
|
||||
|
||||
.DS_Store
|
||||
|
||||
index/index.json
|
||||
@@ -0,0 +1,49 @@
|
||||
## Hatchet Python Quickstart
|
||||
|
||||
This is an example project demonstrating how to use Hatchet with Python. For detailed setup instructions, see the [Hatchet Setup Guide](https://docs.hatchet.run/home/setup).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before running this project, make sure you have the following:
|
||||
|
||||
1. [Python v3.10 or higher](https://www.python.org/downloads/)
|
||||
2. [Poetry](https://python-poetry.org/docs/#installation) for dependency management
|
||||
|
||||
## Setup
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/hatchet-dev/hatchet-python-quickstart.git
|
||||
cd hatchet-python-quickstart
|
||||
```
|
||||
|
||||
2. Set the required environment variable `HATCHET_CLIENT_TOKEN` created in the [Getting Started Guide](https://docs.hatchet.run/home/hatchet-cloud-quickstart).
|
||||
|
||||
```bash
|
||||
export HATCHET_CLIENT_TOKEN=<token>
|
||||
```
|
||||
|
||||
> Note: If you're self hosting you may need to set `HATCHET_CLIENT_TLS_STRATEGY=none` to disable TLS
|
||||
|
||||
3. Install the project dependencies:
|
||||
|
||||
```bash
|
||||
poetry install
|
||||
```
|
||||
|
||||
### Running an example
|
||||
|
||||
1. Start a Hatchet worker by running the following command:
|
||||
|
||||
```shell
|
||||
poetry run python src/worker.py
|
||||
```
|
||||
|
||||
2. To run the example workflow, open a new terminal and run the following command:
|
||||
|
||||
```shell
|
||||
poetry run python src/run.py
|
||||
```
|
||||
|
||||
This will trigger the workflow on the worker running in the first terminal and print the output to the the second terminal.
|
||||
@@ -0,0 +1,4 @@
|
||||
from hatchet_sdk import Hatchet
|
||||
|
||||
# Initialize Hatchet client
|
||||
hatchet = Hatchet()
|
||||
Generated
+1255
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
[tool.poetry]
|
||||
name = "hatchet-python-quickstart"
|
||||
version = "0.1.0"
|
||||
description = "Simple Setup to Run Hatchet Workflows"
|
||||
authors = ["gabriel ruttner <gabe@hatchet.run>"]
|
||||
readme = "README.md"
|
||||
package-mode = false
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
hatchet-sdk = "1.0.0a1"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
simple = "src.run:main"
|
||||
worker = "src.worker:main"
|
||||
@@ -0,0 +1,16 @@
|
||||
import asyncio
|
||||
|
||||
from .workflows.first_task import SimpleInput, first_task
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
result = await first_task.aio_run(SimpleInput(message="Hello World!"))
|
||||
|
||||
print(
|
||||
"Finished running task, and got the transformed message! The transformed message is:",
|
||||
result.transformed_message,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,15 @@
|
||||
from .hatchet_client import hatchet
|
||||
from .workflows.first_task import first_task
|
||||
|
||||
|
||||
def main() -> None:
|
||||
worker = hatchet.worker(
|
||||
"first-worker",
|
||||
slots=10,
|
||||
workflows=[first_task],
|
||||
)
|
||||
worker.start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,21 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from hatchet_sdk import Context
|
||||
|
||||
from ..hatchet_client import hatchet
|
||||
|
||||
|
||||
class SimpleInput(BaseModel):
|
||||
message: str
|
||||
|
||||
|
||||
class SimpleOutput(BaseModel):
|
||||
transformed_message: str
|
||||
|
||||
|
||||
# Declare the task to run
|
||||
@hatchet.task(name="first-task", input_validator=SimpleInput)
|
||||
def first_task(input: SimpleInput, ctx: Context) -> SimpleOutput:
|
||||
print("first-task task called")
|
||||
|
||||
return SimpleOutput(transformed_message=input.message.lower())
|
||||
Reference in New Issue
Block a user