> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/sdks/unitlabclient-and-resource-namespaces.md). Agents can also search and read this documentation through its [MCP server](https://docs.unitlab.ai/~gitbook/mcp).

# UnitlabClient and resource namespaces

Create a UnitlabClient, reach every resource through its namespaces, and close it cleanly.

`UnitlabClient` is the entry point of the Python SDK. It holds one HTTP connection pool and exposes each Unitlab resource as a namespace.

```python
from unitlab import UnitlabClient

client = UnitlabClient()              # reads UNITLAB_API_KEY and UNITLAB_API_URL
try:
    for project in client.projects.list():
        print(project.id, project.name)
finally:
    client.close()
```

`UnitlabClient(api_key=None, api_url=None)` takes the key and URL from its arguments, then the environment, then `unitlab configure`. See [Authentication and API keys](https://docs.unitlab.ai/api-sdk-cli/get-started/authentication-and-api-keys.md).

## Namespaces

| Namespace                 | Returns                     | Use it for                                                       |
| ------------------------- | --------------------------- | ---------------------------------------------------------------- |
| `client.projects`         | `Project`                   | List, get and create projects; upload, attach, workflow, imports |
| `client.assets`           | `Asset`, `Folder`           | Workspace library files, folders, custom metadata, Data Groups   |
| `client.datasets`         | `Dataset`, `DatasetVersion` | Curated drafts and published versions                            |
| `client.ontologies`       | `Ontology`                  | Reusable class and property definitions                          |
| `client.releases`         | `Release`                   | Create, wait for and download exports                            |
| `client.cloud_storages`   | `CloudStorage`              | Saved S3, GCS, Azure and S3-compatible connections               |
| `client.embedding_spaces` | `EmbeddingSpace`            | Your own vectors and similarity search                           |

Three shortcuts work without a project handle:

| Call                                                                  | Returns                                      |
| --------------------------------------------------------------------- | -------------------------------------------- |
| `client.get_workflow_task(task_id)`                                   | `WorkflowTask`, for Agent and model services |
| `client.get_data_unit(project_id, unit_id)`                           | One `DataUnit`                               |
| `client.attach_dataset(project, dataset, version="latest", fps=None)` | `AttachResult`                               |

## Handles and IDs

Every namespace returns typed handles. A handle keeps its raw API row in `.raw` and has methods that act on it:

```python
project = client.projects.get("PROJECT_ID")
batch = project.upload("./images")
release = client.releases.create(project, export_type="COCO")
```

Wherever a method takes a resource, you can pass the handle or its ID string.

## Client lifetime

* Create one client per process or worker and reuse it. It is safe to share across sequential calls.
* Call `client.close()` when you finish, or wrap the work in `try`/`finally`.
* Create a separate client in each process when you use multiprocessing.

## Timeouts and retries

| Setting              | Value                                                               |
| -------------------- | ------------------------------------------------------------------- |
| HTTP request timeout | 60 seconds (600 seconds for release creation)                       |
| Connection errors    | Retried 3 times, after 0, 0.5 and 1 second                          |
| Proxies              | `HTTPS_PROXY`, `HTTP_PROXY`, `ALL_PROXY` and `NO_PROXY` are honored |

HTTP errors are not retried automatically. See [Exceptions, timeouts, and retries](https://docs.unitlab.ai/api-sdk-cli/sdks/exceptions-timeouts-and-retries.md).

## Related

[Python SDK quickstart](https://docs.unitlab.ai/api-sdk-cli/get-started/python-sdk-quickstart.md) · [Return types and fields](https://docs.unitlab.ai/api-sdk-cli/sdks/return-types-and-fields.md) · [Projects](https://docs.unitlab.ai/api-sdk-cli/sdks/projects.md)
