# Automate with the Python SDK

The AlgoFly Python SDK automates DataHub workflows while using the same authorization, plan limits, and data validation as the app.

You do not need the SDK for everyday browsing and labeling. It becomes useful when the same steps need to run repeatedly: import a dataset, download each approved version, submit a planned experiment, or collect reports for comparison.

| Repetitive task | SDK workflow |
| --- | --- |
| Bring labeled data from another tool | Folder/archive importer with a supported format |
| Review or update labels in code | Image records and revision-bound annotation snapshots |
| Supply training data to another environment | Version export and download |
| Track several experiments | Training configurations, runs, and sweeps |
| Collect model outputs | Artifact downloads and retained inference results |

## Install and authenticate

Open the [SDK documentation](/sdk-docs) for the installation command and examples appropriate to this deployment. The Python import is:

```python
from algofly import AlgoFly
```

Configure the DataHub URL and API key using the documented client options or environment variables. Do not put credentials in shared notebooks, screenshots, committed files, or job parameters.

## Build a small workflow first

1. Verify authentication and list your workspaces.
2. Select the intended project explicitly.
3. Upload a small labeled sample or read a few existing images.
4. Inspect dimensions, classes, splits, and annotations.
5. Create a dataset version, wait for its result, and generate a compatible export.
6. Download and inspect the archive before automating a larger batch.

The SDK includes a command-line importer for images, folders, and supported dataset archives. Use an explicit format when automatic recognition cannot distinguish the layout reliably.

## Edit annotations safely

When your deployment returns annotation revision metadata, keep it with the annotation snapshot and use the revision-aware save methods described in its SDK guide. Reload changed pixels before reapplying geometry from an older draft.

For bulk operations, inspect each item's result. A partial failure does not mean every image was updated, and it should not erase your local failed draft.

## Handle long-running work

Creation and execution are separate from waiting. After a timeout, inspect the existing version, export, or run instead of automatically submitting another operation.

For operations with idempotency keys, retry with the same key and identical inputs. A terminal failed or cancelled run can be returned by a wait method; check its status before using outputs as a successful model.

Recovery-required exports and retained worker warnings need inspection. Do not implement an unconditional regenerate, retrain, or delete loop around them.

## Choose the correct API surface

Use project data methods for dataset images and labels, artifacts for files, and training or inference methods for supported compute workflows. An uploaded model file does not by itself authorize arbitrary code execution or establish recipe compatibility.

See the [SDK reference and examples](/sdk-docs) for exact method signatures, accepted formats, resource assessment, training configurations, conversion, inference history, and sweeps.
