Metadata-Version: 2.4
Name: geni-bioinfo
Version: 0.2.0
Summary: Python client for the GENI Workflows
Project-URL: Homepage, https://geni-bioinfo.com.br
Project-URL: Repository, https://github.com/geni-bioinfo/geni-python
Project-URL: Bug Tracker, https://github.com/geni-bioinfo/geni-python/issues
License: MIT
License-File: LICENSE
Keywords: bioinformatics,cloud,geni,genomics,nextflow,workflows
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: requests>=2.28
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pyyaml; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# geni-bioinfo

[![PyPI version](https://img.shields.io/pypi/v/geni-bioinfo)](https://pypi.org/project/geni-bioinfo/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)

Python client library for the [GENI Workflows API](https://geni-bioinfo.com.br) — a bioinformatics platform for submitting and managing Nextflow workflow executions on cloud infrastructure.

## Installation

```bash
pip install geni-bioinfo
```

## Quick start

### Authentication

**Option 1 — email and password (JWT):**

```python
from geni import GeniClient

client = GeniClient()
client.auth_login("you@example.com", "your-password")
```

The client keeps the session's refresh token: when the access token expires, the next
request refreshes it once and retries, so long-running scripts stay logged in.
`client.auth_refresh()` renews it ahead of time, and `client.auth_logout()` revokes it.

**Option 2 — static API token:**

```python
from geni import GeniClient

client = GeniClient()
client.auth_token("your-api-token")
```

### Listing everything

List methods return one page (`limit`, default 50; `offset`). Each has an `iter_*` twin
that pages to the end:

```python
from datetime import date

for sub in client.iter_submissions(status="failed", start_date=date(2026, 10, 1)):
    print(sub.id, sub.workflow_name)
```

### Errors

```python
from geni.exceptions import GeniAPIError

try:
    client.queue_create("spot", environment_id, max_vcpus=0)
except GeniAPIError as e:
    print(e.status_code, e.problem_type)   # e.g. 400 and None, or 409 and "resource-disabled"
    for err in e.field_errors:             # [{"field": ..., "message": ...}]
        print(err["field"], err["message"])
```

The API URL defaults to `https://workflows-api.geni-bioinfo.com.br`. Override it with the `GENI_API_URL` environment variable or the `api_url` constructor argument.

### Core workflow

```python
from geni import GeniClient

client = GeniClient()
client.auth_token("your-api-token")

# 1. Upload a workflow
wf = client.workflow_create(
    name="hello-world",
    version="1.0.0",
    file_path="hello.nf",
)
print(wf.name, wf.version)

# 2. Discover available engines and queues
engines = client.engine_list(status="active")
queues  = client.queue_list(status="active")

# 3. Submit the workflow
submission = client.submission_create(
    workflow_name="hello-world",
    engine_id=engines[0].id,
    queue_id=queues[0].id,
    output="s3://my-bucket/runs/hello-001",
    params_path="params.yml",
)
print(submission.submission_id, submission.status)

# 4. Poll status
sub = client.submission_get(submission.submission_id)
print(sub.status)

# 5. Stream logs
print(client.submission_logs(submission.submission_id, text=True))
```

### Tagging

Tag keys live in one registry shared by workflows and submissions, and must be created first:

```python
client.tag_create("client")
client.tag_create("project")

# Workflow tags apply to every version and are inherited by its submissions.
client.workflow_create(
    name="hello-world", version="1.0.0", file_path="hello.nf",
    tags={"client": "lab", "project": "x"},
)
client.workflow_update_tags(
    "hello-world",
    edit=[{"key": "client", "value": "acme"}],
    remove=["project"],
)
client.workflow_list(tags={"client": "acme"})

# A submission tag overrides the workflow's value for the same key.
client.submission_create(..., tags={"client": "other"})
```

Tags are copied onto the submission when it is created, so editing a workflow's tags later does
not change submissions that already exist.

### Restore and immutability *(admin only)*

```python
# Bring back a soft-deleted version (raises GeniAPIError with status_code 409 if it isn't deleted),
# or a whole workflow with all its versions.
client.workflow_version_restore("hello-world", "1.0.0")
client.workflow_restore("hello-world")

# Immutability only blocks overwriting a version by re-uploading the same name and version.
v = client.workflow_version_set_immutable("hello-world", "1.0.0", True)
print(v.immutable)  # True
```

### Enable and disable resources

Disable an engine or queue to retire it without deleting its cloud resources. New submissions and
retries that target it are rejected with `GeniAPIError` (`status_code == 409`); running
submissions continue. Engines and queues need an admin (or GENI support); environments can only
be toggled by GENI support, who must pass `tenant_id`.

```python
client.queue_disable(queue_id)
client.queue_list(enabled=False)   # what is currently disabled
client.queue_enable(queue_id)
```

## API reference

### `GeniClient`

| Method | Description |
|---|---|
| `auth_login(email, password)` | Authenticate with email + password (JWT) |
| `auth_token(token)` | Authenticate with a static API key |
| `auth_refresh()` / `auth_logout()` | Renew or revoke the login session |
| `user_list()` | List platform users *(admin only)* |
| `environment_list(status, enabled)` | List cloud environments *(admin only)* |
| `engine_list(status, environment_id, engine, enabled)` | List engines, optionally filtered by environment, engine type (`nextflow`/`cromwell`) or enabled flag *(admin only)* |
| `queue_list(status, environment_id, execution_mode, enabled)` | List job queues, optionally filtered by environment, execution mode (`spot`/`on-demand`) or enabled flag *(admin only)* |
| `engine_enable(id)` / `engine_disable(id)` | Allow or reject new submissions to an engine *(admin or support)* |
| `queue_enable(id)` / `queue_disable(id)` | Allow or reject new submissions to a queue *(admin or support)* |
| `environment_enable(id, tenant_id)` / `environment_disable(id, tenant_id)` | Allow or reject new submissions to everything in an environment *(GENI support only)* |
| `storage_list(status)` | List cloud storage resources *(admin only)* |
| `environment_create/update/delete`, `engine_create/update/delete`, `queue_create/update_ami/delete`, `storage_create/delete`, `plugin_create/delete`, `registry_create/delete` | Manage infrastructure; asynchronous, poll the matching `*_get` *(admin; environments support only)* |
| `registry_auth(id)` | Short-lived ECR push credentials *(admin only)* |
| `iter_*` (`iter_submissions`, `iter_tasks`, `iter_queues`, …) | Every item of the matching `*_list`, paging through `limit`/`offset` |
| `workflow_create(name, version, file_path, tags=..., ...)` | Upload and register a workflow version |
| `workflow_list(tags=...)` | List all registered workflow versions, optionally filtered by tag |
| `workflow_update_tags(name, add, edit, remove)` | Add, change, or remove tags on a workflow |
| `workflow_versions(name, deleted=False)` | List a workflow's active (or soft-deleted) versions |
| `workflow_delete(name)` / `workflow_version_delete(name, version)` | Soft-delete a workflow (all versions) or one version |
| `workflow_restore(name)` / `workflow_version_restore(name, version)` | Restore a soft-deleted workflow or version *(admin only)* |
| `workflow_version_set_immutable(name, version, immutable)` | Change a version's overwrite guard *(admin only)* |
| `submission_create(workflow_name, engine_id, queue_id, output, params_path, ...)` | Submit a workflow for execution; `nextflow_profile="test,docker"` selects Nextflow profiles |
| `submission_list(status, from_, to, start_date, end_date, limit, offset, ...)` | List submissions (`iter_submissions` for all) |
| `submission_get(id)` | Fetch a single submission by ID |
| `submission_inputs(id, output_file=None)` | Download the original JSON/YAML inputs as bytes, optionally writing a file |
| `submission_cancel(id)` | Cancel a running submission |
| `task_list(submission_id)` | List tasks for a submission |
| `task_logs(submission_id, task_id, text)` | Fetch task log entries |
| `submission_logs(submission_id, text)` | Fetch submission-level Nextflow logs |
| `cost_summary(start_date, end_date, daily=False)` | Total cost, or per day *(analytics:read)* |

### Exceptions

| Exception | Raised when |
|---|---|
| `GeniConfigError` | `auth_login()` or `auth_token()` was not called before a request |
| `GeniAuthError` | Invalid credentials or insufficient permissions (HTTP 401/403) |
| `GeniNotFoundError` | A resource ID does not exist (HTTP 404) |
| `GeniAPIError` | Any other unexpected HTTP error; exposes `.status_code`, `.method`, `.url`, `.response_body` |

Every exception also has `.problem_type` (the API's error token, or `None`) and `.field_errors`.

## Tutorial

An interactive Jupyter notebook is available in [`docs/tutorial.ipynb`](docs/tutorial.ipynb).

## License

MIT — see [LICENSE](LICENSE).
