Metadata-Version: 2.5
Name: iota-hub
Version: 0.2.0
Summary: Client library and CLI for the IOTA Hub public API (occultation observation submission)
Project-URL: Homepage, https://github.com/skycarl/iota-hub-python
Project-URL: Documentation, https://iota-hub.com/developers
Project-URL: Source, https://github.com/skycarl/iota-hub-python
Author: IOTA Hub
License: MIT License
        
        Copyright (c) 2026 Skyler Carlson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api-client,astronomy,cli,iota,occultation
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Astronomy
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: platformdirs>=4
Requires-Dist: pydantic>=2.6
Requires-Dist: tomli>=2; python_version < '3.11'
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# iota-hub

[IOTA Hub](https://iota-hub.com) is where observers of asteroid occultations send
their observations to IOTA: a report, a light curve, an instrument log, and
optionally a VizieR file, checked and reviewed in one place instead of by email.
`iota-hub` is the command-line tool and Python library for its public API v1 —
it creates the draft, uploads the files, runs the observer checks, and submits
when the checks are clean. It is meant for observers who want their submission
scripted or reduced to one command, and for AI agents acting on an observer's
behalf. There are three ways in, in the order you should try them: **the CLI
first**, the **Python library** second when you are building something of your
own, and the **raw HTTP API** last, documented at
<https://iota-hub.com/developers/api>.

## Quickstart (CLI)

No install needed if you have [uv](https://docs.astral.sh/uv/):

```bash
uvx iota-hub auth login          # paste your API key when prompted
cd 20180305_9721_Doty_Observer_POS
uvx iota-hub submit
```

Prefer it on your PATH: `uv tool install iota-hub`, or `pipx install iota-hub`,
and then run `iota-hub` instead of `uvx iota-hub`.

A clean run looks about like this (progress on stderr, the result on stdout):

```
Creating draft (4 files)...
Uploading report (1/4)...
Uploading lightcurve (2/4)...
Uploading log (3/4)...
Uploading attachment field_notes.png (4/4)...
Finalizing draft...
Waiting for checks...

Submitted obs_01HZY4A1K2QX
  report      20180305_9721_Doty_Observer_POS.xlsx
  lightcurve  20180305_9721_Doty_Observer_POS.csv
  log         20180305_9721_Doty_Observer_POS_pyote_log.txt
  attachment  field_notes.png
  checks      complete, 0 open findings
```

`submit` is the whole job: it creates a draft, uploads each file straight to
storage (files never travel through the API), finalizes, waits for the observer
check run, and submits the observation when — and only when — the draft comes
back `ready`. If the run leaves open findings, or something required is still
missing, it does not submit: the draft stays in your Drafts, the findings are
printed with the exact commands that resolve them, along with the draft's
`Web:` link to finish it in the browser, and the exit code is `4`. Nothing is
ever guessed and nothing is ever thrown away — a draft it could not submit is
recoverable in the web app. Submitting something that is already submitted is
not an error either: it reports `submitted`.

**Skipped checks are said out loud.** A check that could not run never blocks
submit, so after "Waiting for checks..." `submit` prints a `WARNING` block on
stderr naming every skipped check and why. The usual one is check 11 (near the
predicted time), which needs an Occult Watcher Cloud link: the Hub matches the
OWC event itself after the upload, and when it cannot choose (several
candidates, a mismatch, nothing found) the block lists the candidates and the
commands to settle it — `iota-hub drafts owc <id> --pick <owc_event_id>`,
`--link <url>` or `--none`. Use `submit --draft` if you want to settle it
before submitting.

Useful variations:

- `iota-hub submit --draft` — do everything except the final submit, so you can
  review it in the web app first.
- `iota-hub submit --dry-run` — print the slot mapping, the file sizes and the
  target, and call nothing.
- `iota-hub submit --json` — one JSON document on stdout, for scripts and agents.
- `iota-hub submit --no-wait` — return after the upload with the draft id and
  its `Web:` link; `--timeout S` changes how long it waits (default 10 minutes).

Not sure whether an earlier run already created the draft? Ask before creating
a second one — it finds your own draft or submission by what it observed, or
says whether the event exists:

```bash
iota-hub observations check --asteroid-id 9721 --asteroid-name Doty \
    --star-id 1234-56789 --date 2018-03-05
```

## Which file goes where

`submit` takes a directory (the current one by default) and maps its files onto
the five slots by rules only. The observer naming convention
(`YYYYMMDD_<number>_<name>_<lastname>_POS|NEG[-X]`, see
<https://iota-hub.com/data-submission>) already carries enough signal, so there
is no classification and no content sniffing:

| Slot              | Rule                                                     | Required |
| ----------------- | -------------------------------------------------------- | -------- |
| `report`          | exactly one `.xlsx` / `.xls`, or a Tangra `.json` report | yes      |
| `lightcurve`      | at most one `.csv`                                       | POS/UNSURE |
| `log`             | at most one `.txt` whose name contains `log`             | POS/UNSURE |
| `vizier`          | at most one `.dat`                                       | no       |
| `aperture_record` | at most one Tangra `.lc` or PyMovie `.pymovie`           | no       |

A folder with no report stops the command before anything is sent. Only the Hub
knows the result, once it has read the report, so a POS or UNSURE observation
with no light curve or log becomes a draft that lists what it still needs.

The listing is non-recursive and skips subdirectories and dotfiles; extensions
match case-insensitively, so `.CSV` is a light curve.

The NA spreadsheet is still the primary report; a folder holding both a
spreadsheet and a `.json` is ambiguous, so name the one you mean with
`--report`. The aperture record has its own slot (up to 500 MB), so it is not
an attachment.

Anything the rules do not claim — `field_notes.txt`, a PyOTE `.png` — is
uploaded as an **attachment**, just like the web app's
"Optional Attachments". The web app's limits apply, and are checked before
anything is created, so a folder that breaks one fails whole (exit code `2`)
with every offending file named:

- at most **25** attachments per observation,
- at most **50 MB** each,
- no executables or scripts (`.exe`, `.bat`, `.cmd`, `.sh`, `.ps1`, `.js`,
  `.py`, `.php`, `.pl`, `.rb`, `.jar`, `.msi`, `.dll`, `.so`).

`--no-attachments` uploads only the five slots and lists the rest as **not
uploaded**; `--attach PATH` (repeatable) adds a file from outside the folder.
`--dry-run` shows the attachments too. Afterwards,
`iota-hub drafts files add <id> attachment <path>` adds one and
`iota-hub drafts files rm <id> attachment <attachment_id>` removes one (the ids
are in `iota-hub drafts show <id>`).

**Ambiguity is an error, never a guess.** Two candidates for one slot, or no
report, stops the command with the names of the files involved and
the flag that settles it. The overrides are `--report PATH`,
`--lightcurve PATH`, `--log PATH`, `--vizier PATH` and `--aperture-record PATH`;
each is checked only for the slot's extension. The "contains `log`" rule only
tells two `.txt` files in a folder apart, so `--log PATH` takes any `.txt` — a
Tangra fit log or `notes.txt` alike.

**Correcting a submitted observation** is the same command as fixing a draft:
`iota-hub drafts files add <id> <slot> <path>` replaces the file and marks the
observation `amended`. A replacement report must still describe the same
observation (otherwise `identity_changed`, exit code `2`, and nothing changes),
and once its event is in review the Hub refuses (`already_processed`, exit code
`1`) — ask a coordinator then.

## Getting a key

Sign in to IOTA Hub and open the **Developers** page (`/developers`); the
**API keys** section is there. The key is shown once, is stored hashed, and you
may have up to 10.

- **Scopes**, fixed when the key is created: `read` for every read,
  `observations:write` for every write. A key missing the scope a call needs is
  `403 insufficient_scope`.
- **Lifetime**, chosen when the key is created: 30 days, 90 days, 1 year (the
  default), or never. An expired key is `401 expired_api_key`.
- A key **acts as its owner** — exactly what that account can do in the web app,
  nothing more.

Give the key to the tool in one of two ways, never as a command-line argument
(it would land in your shell history and in `ps`):

```bash
iota-hub auth login              # prompts with hidden input, stores it
export IOTA_HUB_API_KEY=...      # the CI and agent path, no login step
```

`iota-hub auth status` shows which profile is in use, the target base URL and
the identifying prefix of the key (`iotahub_<key_id>_...`, never the secret),
and makes one cheap read to say whether the key is actually valid.
`iota-hub auth logout` removes a stored profile.

Both select a profile like every other command: `--profile`, then
`IOTA_HUB_PROFILE`, then the config file's `default_profile` (the first profile
you saved), then `default`, and both print the one they used. If it already
holds a key, `auth login` asks before replacing it on a terminal (`--yes` skips
the question); with a piped key, it replaces the key and says so on stderr.

Profiles keep a key **and** its base URL together, so a development key is never
sent to production or the reverse:

```bash
iota-hub auth login --profile dev --base-url <dev base URL>
iota-hub submit --profile dev          # or IOTA_HUB_PROFILE=dev
```

`--json`, `--profile` and `--base-url` are accepted after the subcommand, as
above, and before it (`iota-hub --profile dev submit`) — whichever reads better.
When both carry a value, the one after the subcommand wins.

Whenever the resolved target is not the production default, the CLI prints
`Target: <base URL>` on stderr before acting, so a test run is never mistaken
for a real submission. Settings resolve flag > environment > config file >
default, and the config file lives where the platform puts configuration:

| Platform | Path                                                     |
| -------- | -------------------------------------------------------- |
| Linux    | `~/.config/iota-hub/config.toml`                          |
| macOS    | `~/Library/Application Support/iota-hub/config.toml`      |
| Windows  | `%LOCALAPPDATA%\iota-hub\config.toml`                     |

On POSIX the file is written `0600`. On Windows the protection is the ACL on
your user profile directory; the tool does not set permissions itself. There is
no OS keyring integration.

## For scripts and agents

- **`--json` works on every command**: exactly one JSON document on stdout and
  nothing else. Errors are JSON too, on **stderr**, in the API's problem-details
  shape plus the HTTP status, the retry wait and the exit code:
  `{"code": "open_findings", "message": "...", "hint": "...", "details": {}, "status": 409, "retry_after": null, "exit_code": 4}`.
  That document is all a failed run writes to stderr; `Target:` and progress lines
  appear only once a run has succeeded. An error after a draft was created says
  which one in `details.observation_id`.
  Branch on `code`, never on `message`. A bad invocation is JSON too, as
  `usage_error` with exit code `2`.
- **Exit codes** — branch on these rather than parsing output:

  | Code | Meaning                  | Typical cause                                                             |
  | ---- | ------------------------ | ------------------------------------------------------------------------- |
  | `0`  | success                  | also `--draft`, `--dry-run` and `--no-wait`, which end where you asked     |
  | `1`  | error                    | any other failure, including `5xx` and network failures                   |
  | `2`  | usage                    | bad flags, missing argument, an ambiguous or incomplete slot mapping, a replacement report for another observation (`identity_changed`) |
  | `3`  | auth                     | no key configured, or the API rejected it                                 |
  | `4`  | open findings / not ready | findings to fix or dismiss, something required missing, or a wait timeout |
  | `5`  | rate limited             | still rate limited after the built-in retries                             |

- **`iota-hub guide`** prints the full workflow guide, bundled in the package —
  no network, and the same text an agent can read before acting.
- **[`SKILL.md`](https://github.com/skycarl/iota-hub-python/blob/main/SKILL.md)** in this repository is a ready-made skill for Claude
  Code or any agent that reads `SKILL.md`. Point your agent at it.
- **Never prompts when stdin is not a TTY.** Destructive commands take `--yes`.
- On a terminal, output is colored and spaced for reading; it is plain, colorless
  text when piped, under `--json` or when `NO_COLOR` is set, and is plain ASCII
  by default so a non-UTF-8 Windows console survives it.
- The literal next command for every action the API says is available is
  printed in human output and returned as `next_commands` in `submit --json`,
  so neither a person nor an agent has to translate a verb into a command.
- `submit --json` also carries `skipped_checks` (every check that did not run,
  with its reason) and `owc_commands` (the commands that settle an unresolved
  OWC link; empty when there is nothing to settle). Neither changes the exit
  code: they warn, they never block.

## Python library

The library is the same code the CLI is built on, importable on its own. Its
guide is [`docs/library.md`](docs/library.md), also at
<https://iota-hub.com/developers/library>.

```python
import os
from iota_hub import Client

with Client(api_key=os.environ["IOTA_HUB_API_KEY"]) as client:
    result = client.submit_folder("path/to/observation")
    print(result.outcome, result.observation_id)

    if result.outcome == "needs_attention":
        checks = result.observation.checks
        for finding in checks.findings if checks else []:
            print(finding.fingerprint, finding.message, finding.how_to_fix)
        # Fix one and the draft re-arms its checks:
        client.replace_file(result.observation_id, "lightcurve", "fixed.csv")

    for observation in client.iter_observations(submission_status="draft"):
        print(observation.observation_id, observation.submission_status)

    client.download_files("observation", result.observation_id, "downloads/")
```

`result.outcome` is the vocabulary to branch on: `submitted` (also when it
already was), `ready` (clean but left a draft), `needs_attention` (findings,
something missing, or the run errored), or `draft` (`wait=False`, uploaded and
finalized but not waited on). `result.observation.web_url` is the observation in
the web app, and `result.observation.status` is the derived `draft` /
`submitted` / `amended` / `locked`. `client.check_observation(asteroid_name=...,
star_id=..., observed_date="YYYY-MM-DD", asteroid_id=...)` is the lookup before
a create.

Two layers, deliberately kept apart. The **transport** layer is one method per
public API operation (`create_draft`, `submit_draft`, `list_events`,
`list_observation_files`, ...), returning hand-written pydantic models. The
**workflow** layer is what the API cannot do for you: `submit_folder`,
`submit_files`, `wait_for_checks`, `replace_file`, `download_files`, and the
folder-to-slot mapping in `iota_hub.files`.

Retries (`429`/`5xx`, honouring `Retry-After`), one idempotency key per logical
call, and the base64 SHA-256 declared on every upload are all handled for you.
Errors are one exception type, `IotaHubError`, carrying `.code`, `.message`,
`.hint`, `.details`, `.status` and `.retry_after`; the subclasses `AuthError`,
`RateLimitError`, `NotFoundError`, `ConflictError`, `RequestError` and
`TransportError` group the codes by category, so you can catch broadly without
enumerating them. Models ignore fields they do not know, so an additive API
change never breaks an installed version.

## Environments

The default target is production, `https://api.iota-hub.com`. **The public API
is not live in production yet** — its release is pending, and until then the
development deployment is where third-party developers build: sign up there,
create a key, and use a `dev` profile. The development base URL is published on
that site's `/developers` page; no non-production URL is baked into this
package.

```bash
iota-hub auth login --profile dev --base-url <the dev base URL>
iota-hub observations list --profile dev
```

`--base-url` (and `IOTA_HUB_BASE_URL`) is the **API base**; the client appends
`/public/v1` itself. Local development against a checkout of the API is
`--base-url http://localhost:8000`.

## Under the hood: the HTTP API

Everything here is a client of one frozen, versioned HTTP surface, `/public/v1`,
which stays public for anyone the CLI and the library do not fit. It is the hard
way — presigned S3 uploads, polling, idempotency keys — which is exactly why
this package exists.

The raw-HTTP walkthrough is at <https://iota-hub.com/developers/api>
(interactive reference at `/developers/reference`, the raw workflow guide at
`/developers/guide.md`; keys are on `/developers`). Porting a client to another language starts from
[`spec/openapi.json`](https://github.com/skycarl/iota-hub-python/blob/main/spec/openapi.json), vendored here and checked against the
live document in CI, and
[`docs/client-conventions.md`](https://github.com/skycarl/iota-hub-python/blob/main/docs/client-conventions.md), which specifies
everything the API itself does not: configuration, retries, polling, folder
mapping, exit codes and output.

## Requirements

Python 3.10 or newer, on Windows, macOS or Linux. Runtime dependencies are
`httpx`, `pydantic`, `typer` and `platformdirs`.

## Versioning

Semantic versioning, `0.x` until the public API's production release. A
**major** bump is removing a command or a flag, or changing the shape of a
`--json` document. New commands, new optional flags and new fields in a `--json`
document are additive and are not.

## Contributing

Issues and pull requests go to
[skycarl/iota-hub-python](https://github.com/skycarl/iota-hub-python) — including
issues about the API itself (a wrong status code, a missing filter, an unclear
finding), which the maintainer takes to the API from there.

## License

MIT. See [LICENSE](LICENSE).
