A prefect extension giving prefect tasks super powers
Motivation
Prefect tasks plus added functionality to enforce type checking and help in debugging helping to reduce negative engineering!
How to setup
Using pip:
pip install supreme_task
How to use
Runtime type checking
Get runtime type checking thanks to typeguard by importing the @task decorator from supreme_task instead of prefect.
See the example run.py file:
from supreme_task import task
@task
def add(x: int, y: int) -> int:
return x + y
add.fn(x="1", y=2)
Running python run.py will raise the following exception:
Traceback (most recent call last):
File "run.py", line 9, in <module>
add.fn(x="1", y=2)
File "run.py", line 5, in add
def add(x: int, y: int) -> int:
File "supreme-task-py38/lib/python3.8/site-packages/typeguard/_functions.py", line 135, in check_argument_types
check_type_internal(value, annotation, memo)
File "supreme-task-py38/lib/python3.8/site-packages/typeguard/_checkers.py", line 761, in check_type_internal
raise TypeCheckError(f"is not an instance of {qualified_name(origin_type)}")
typeguard.TypeCheckError: argument "x" (str) is not an instance of int
Persistence of flow run inputs
Get persistence of flow run inputs by importing the @task decorator from supreme_task instead of prefect to help with debugging.
i.e. given a file run.py:
from supreme_task import task
from prefect import flow
from prefect.filesystems import LocalFileSystem
@task
def faulty_add(x: int, y: int) -> int:
if x == 1:
raise ValueError("x is 1")
return x + y
@flow(result_storage=LocalFileSystem(basepath="results/"))
def my_flow() -> None:
faulty_add(x=1, y=2)
my_flow()
We update our prefect configuration to enable result persistence:
prefect config set PREFECT_RESULTS_PERSIST_BY_DEFAULT=true
We then run the flow by running python run.py
We now inspect the results directory:
$ tree results
results
├── 514aaa4ae0134405a639cbd9a17365da
├── b662c63ff9854b0e9383d7f6cf0a5b76
└── inputs
└── faulty_add
└── 2023-06-10T10-47-04+0000
The inputs for failed task runs are saved under results/inputs/<task_name>/<start_run_time>.
Metadata
Release files for supreme-task 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| supreme_task-0.1.1.tar.gz | 5.4 kB | Without provenance | Details for supreme_task-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| supreme_task-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for supreme_task-0.1.1-py3-none-any.whl |
Total release size: 12.3 kB
Release files / supreme_task-0.1.1.tar.gz
| Download URL | supreme_task-0.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0da8e761a1db2012fb8450668ea925cef80803509cd05ed3deaac92a7ea666f2
|
|
BLAKE2b-256 checksum How to use checksums |
0b74ecd026c6e849affc2a9ad07f6a36aabfb477aa1938a75f1ca86e5d21c3dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.0 CPython/3.8.7 Darwin/22.5.0
|
Release files / supreme_task-0.1.1-py3-none-any.whl
| Download URL | supreme_task-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78549dc4fc96cbd2878bdaeca0a2bc1e780ca74a45d95ed3298f0b08dbe55639
|
|
BLAKE2b-256 checksum How to use checksums |
67f0506ed805bfe1bd2b7465ce9f24cdef28ebff240e42303267e7d2d8f86854
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.0 CPython/3.8.7 Darwin/22.5.0
|
Security for supreme-task 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.