Orchestra Python SDK
This is a lightweight SDK that allows Orchestra to interact with self-hosted applications (Tasks).
The basic premise is for your self-hosted Task to send back status updates and logs to Orchestra. This is done via HTTP requests. The Task is started by Orchestra.
Installation
pip install orchestra-sdk
You initialise the package by creating an instance of the OrchestraSDK class. It requires the API key that will connect with Orchestra - this can be found in your settings page. Orchestra will automatically set the other environment variables when the Task is triggered:
ORCHESTRA_WEBHOOK_URL: The URL to send status updates toORCHESTRA_TASK_RUN_ID: The UUID of the Task being executed
There are also optional configuration values:
send_logs: send the contents of a log file to Orchestra associated with the task (default = False)log_file_path: the path to the log file to send to Orchestra (default = "orchestra.log")
from orchestra_sdk.orchestra import OrchestraSDK
orchestra = OrchestraSDK(api_key="your_api_key")
Orchestra recommends retrieving the API key from some secret store that you have configured. If that is not possible, you can set the API key as an environment variable and read that value in your code.
Task decorator
The decorator will handle updating the Task in Orchestra automatically. It will send a RUNNING status update when the function is called, and then send a SUCCEEDED or FAILED status update when the function finishes.
from orchestra_sdk.orchestra import OrchestraSDK
orchestra = OrchestraSDK(api_key="your_api_key")
@orchestra.run()
def my_function(arg1, arg2=1):
print("Running complex process")
- The decorator will firstly read and validate the environment variables
- It will send a
RUNNINGstatus update to Orchestra - Your function will then run
- If an exception is raised, the decorator will send a
FAILEDstatus update to Orchestra - If the function finishes without an error being raised, regardless of the return value, the decorator will send a
SUCCEEDEDstatus update to Orchestra - If
send_logsis enabled, the contents of the logs will also be sent.
Updating Tasks manually
For additional control over when to update the status of the Task, or for sending messages to Orchestra, you can use the update_task method of the OrchestraSDK class.
from orchestra_sdk.enum import TaskRunStatus
from orchestra_sdk.orchestra import OrchestraSDK
orchestra = OrchestraSDK(api_key="your_api_key")
def my_function(arg1, arg2=1):
print("Start my complex process")
orchestra.update_task(status=TaskRunStatus.RUNNING, message="Starting process.")
print("Running complex process")
orchestra.update_task(message="Running process.")
fn_result = complex_process()
if fn_result == 0:
orchestra.update_task(status=TaskRunStatus.SUCCEEDED)
else:
orchestra.update_task(status=TaskRunStatus.FAILED, message="Process failed")
- At least one of
statusormessagemust be provided - If the function fails or throws an exception, Orchestra might not register that the Task has failed, which could have downstream consequences on your pipeline. Consider wrapping your function in a try/except block and calling
update_taskwithstatus=TaskRunStatus.FAILEDin the except block.
Sending logs
To send logs associated to the Task, enable the send_logs flag when initialising the OrchestraSDK class. The logs will be sent to Orchestra when the Task finishes and the decorator is being used.
An example logging configuration is shown below:
import logging
from orchestra_sdk.orchestra import OrchestraSDK
orchestra = OrchestraSDK(
api_key="your_api_key",
send_logs=True,
log_file="a.log"
)
def test_function():
# Setup logging configuration
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# File handler
file_handler = logging.FileHandler("a.log")
file_handler.setLevel(logging.INFO)
# Adding handlers to the logger
logger.addHandler(file_handler)
logger.info("Hello, World!")
Metadata
Release files for orchestra-sdk 0.0.17
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 |
|---|---|---|---|---|
| orchestra_sdk-0.0.17.tar.gz | 10.6 kB | Without provenance | Details for orchestra_sdk-0.0.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| orchestra_sdk-0.0.17-py3-none-any.whl | Python 3 | none | any | Details for orchestra_sdk-0.0.17-py3-none-any.whl |
Total release size: 19.0 kB
Release files / orchestra_sdk-0.0.17.tar.gz
| Download URL | orchestra_sdk-0.0.17.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b5165fbbe8e34f3279b3cb707724566c8d629df7f9b6b17bcbd53ebf18dbc78
|
|
BLAKE2b-256 checksum How to use checksums |
061975ce73edf21e6655b8105af21c3501c2f0752c473a10df9fe93bcb8475ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|
Release files / orchestra_sdk-0.0.17-py3-none-any.whl
| Download URL | orchestra_sdk-0.0.17-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4161959a06275a4963d3f0bf08207989a740f72b55e0c697e0a483d9f4457f25
|
|
BLAKE2b-256 checksum How to use checksums |
a91737ac01e996386766b5a5cccca6981f85c0e1b739e17aab100a28c585f402
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|
Security for orchestra-sdk 0.0.17
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.