> ## Documentation Index
> Fetch the complete documentation index at: https://eddy-ac74d702.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> pip install eddy-solve

```bash theme={null}
pip install eddy-solve
```

The package is standard-library only (Python 3.9+); `numpy` is optional (`Field.to_numpy()`).

## The smallest complete solve

```python theme={null}
from eddy_solve import Eddy

eddy = Eddy("http://127.0.0.1:8080", api_key=None)  # or EDDY_BASE_URL / EDDY_API_KEY
result = eddy.solve_structural(
    geometry={"primitive": {"box": {"lx": 1.0, "ly": 0.2, "lz": 0.2}}},
    material={"id": "steel", "e": 210e9, "nu": 0.3, "rho": 7850, "yield": 250e6},
    loads=[{"region": "x_max", "force": [0, 0, -1000]}],
    constraints=[{"region": "x_min", "fixed": "all"}],
    mesh_opts={"element_size": 0.1},
)
print(result["result_id"], result["cached"], result["metrics"])
u = eddy.field(result, "displacement")   # Field: 3 components per node
print(u.count, "nodes, max |u| =", u.max_magnitude())
assert eddy.verify_report(result["result_id"])["matches"]
```

## Errors

Every failure is an `EddyError` with `.code` (the API's error code — `NOT_FOUND`, `INVALID_GEOMETRY`, `UNAUTHORIZED`, …), `.message` and `.status` (the HTTP status; `0` when the failure was on the client: `TRANSPORT`, `TIMEOUT`).

## Async jobs

A solve above the engine's synchronous threshold (or sent with `mode="async"`) answers `202` with a job handle. By default the client follows it and returns the result; pass `_wait=False` to get the handle back, then `eddy.wait_for_job(job)` or `for event, status in eddy.job_events(job["job_id"]): ...` (the server-sent events, `phase` then `result`).

```python theme={null}
job = eddy.solve_structural(body, mode="async", _wait=False)
result = eddy.wait_for_job(job, timeout=600)
```

## Blobs and fields

Fields are content-addressed blobs. `eddy.blob(blob_id)` fetches bytes through a local cache (`EDDY_CACHE_DIR`, default `~/.cache/eddy-solve/blobs`; a blob id names its bytes forever, so the cache never expires — pass `cache_dir=False` to disable it). `eddy.field(result, "displacement")` decodes one into a `Field` (`components`, `count`, `values` as `array('d')`, `tuples()`, `max_magnitude()`, `to_numpy()`); `eddy.fields(result)` decodes them all.

## In-process (`eddy-native`)

`pip install eddy-native` adds `eddy_native.Engine` — the engine's rigid-body simulation compiled, stepped and rolled out inside your process, byte-identical to `/v1/sim.compile` / `sim.rollout` / `sim.step` (it serialises the very structs the routes serialise) over a content-addressed store in memory or under a directory. `Eddy(base_url, native=eddy_native.Engine())` routes those operations and the blobs they name in-process and everything else over HTTP — one API, one argument to switch transports; `SimEnv(scene, client=that)` runs with no socket. Wheels are built with `maturin` from `bindings/eddy-native`.

## Retries

`retries=3` by default with exponential backoff. Content-addressed operations (a reply carrying `result_id`, `blob_id` or `cached`) and every `GET` are retried on any transport failure or `502` / `503` / `504`; every other `POST` is retried only when the engine was not reached at all (connection refused, `503`). A `429` is retried only when it carries `retry-after` (a rate limit), after the wait it names; one without (`RESOURCE_LIMIT`, `SESSION_LIMIT`) raises at once. Once the retries are spent a `429` / `503` raises with `.retry_after` — the seconds the engine asked for.

## Webhooks

An async solve can carry a `webhook`: when the job finishes the engine POSTs the finished job record to `url` with `x-eddy-signature: blake3=<hex>` (a keyed BLAKE3 MAC over the body, the key derived from `secret`), `x-eddy-job` and `x-eddy-event` (`done` or `error`), three attempts with backoff; the delivery log is on the job record (`eddy.get_job(id)["webhook"]`). A sync solve answers inline and carries none.

```python theme={null}
job = eddy.solve_structural(body, mode="async", webhook={"url": "https://app.example/hooks/eddy", "secret": "s3cret"}, _wait=False)
```

Verify a delivery with the same MAC: `blake3.blake3(body, key=blake3.blake3(secret, derive_key_context="eddy webhook v1").digest()).hexdigest()` (the `blake3` package).

## Usage

`eddy.usage()` is the caller's own meter — the events recorded under the presented API key, newest first, with the summed cost (`GET /v1/usage`; the admin's `/admin/usage` lists every key).

## Offline mode

With the engine as a library (`eddy_native.Library`), `Eddy(native=Library(dir), sync_to=fleet_url, journal=path)` runs every operation in-process and journals each content-addressed solve it answers (not the reads, not the cache hits); `eddy.sync()` replays the journal to the fleet — content addressing makes every replay a cache hit or an identical solve, so the fleet answers the very `result_id` the offline engine answered, and the journal is idempotent. The report names each entry's offline and fleet ids; a failed replay stays in the journal for the next sync.

```python theme={null}
from eddy_native import Library
off = Eddy(native=Library("~/.eddy/store"), sync_to="https://api.eddy.engineering", journal="~/.eddy/journal.ndjson")
res = off.solve_structural(body)          # in-process, journaled
report = off.sync()                       # {"replayed": 1, "failed": 0, "entries": [...]}
```

The conventions for one key per tenant are on the [tenancy page](https://eddy-ac74d702.mintlify.site/sdks/tenancy.md).

## The idiomatic layers

Beside the generated client, one module per domain wraps its routes in the idiom its users already know, every one a thin class over the same `Eddy` (pass `client=` to share one, or `base_url` / `api_key` as before): `eddy_solve.sim` — `SimEnv`, the Gymnasium-shaped environment (`reset()` / `step()` 5-tuple, `.gymnasium()`), `cartpole_scene()`; `eddy_solve.cad` — `CadEnv`, the recipe-editing environment with its feature and goal helpers; `eddy_solve.fea` — `FeaClient` over the study document (vocabulary, validate, lower, edit, episode, sessions); `eddy_solve.cfd` — `CfdClient` and the Fluent-shaped `CaseDocument` / `SettingsProxy` (`case.settings.setup.models.viscous.model = ...`); `eddy_solve.em` — `EmClient` (the transmission lines, cavities, driven and low-frequency solves, the design document, Touchstone); `eddy_solve.eda` — `EdaClient` (the filter / query language, DRC / ERC, the board document); `eddy_solve.optics` — `OpticsClient` and `OpticalSystem` in the ZOS-API idiom (`cooke_triplet()`, lens files in and out, optimise, tolerance); `eddy_solve.design` — `DesignClient` and `DesignLoop` (the agentic design loop with a scripted or Claude proposer); `eddy_solve.motion` — `MotionClient` and the `MotionStudy` builder in the Motion Manager's idiom (elements on mates, solve sync or as a job, series, equilibrium / linearize / sweep, a URDF robot as a study). Each layer raises its own error class (`SimEnvError`, `FeaError`, …), an `EddyError` subclass.

## Quickstarts by domain

```python theme={null}
from eddy_solve import Eddy
from eddy_solve.sim import SimEnv, cartpole_scene
from eddy_solve.optics import OpticsClient, cooke_triplet
from eddy_solve.cfd import CfdClient
from eddy_solve.fea import FeaClient

eddy = Eddy("http://127.0.0.1:8080")

# a Gym-shaped rigid-body environment, deterministic step for step
env = SimEnv(cartpole_scene(), client=eddy, actuators=[0], action_mode="motor_vel")
obs, info = env.reset()
obs, reward, terminated, truncated, info = env.step([0.2])

# a lens in the ZOS-API idiom
res = OpticsClient(client=eddy).solve_optics(cooke_triplet(), catalogs=["SCHOTT"], mode="sync")
print(res["metrics"]["first_order/efl"])

# the Fluent-shaped case document
cfd = CfdClient(client=eddy)
case = cfd.case(cfd.example()["document"])
case.settings.setup.models.viscous.model = "k-omega"
lowered = case.lower()          # the /v1/solve.cfd request the page would send

# the study document of the FEA page
fea = FeaClient(client=eddy)
study = fea.example()
print(fea.validate(study)["counts"], fea.lower(study)["domain"])
```

## Reference

One method per operation, named `snake_case` of the operation id — the [API reference](https://eddy-ac74d702.mintlify.site/api-reference) names each. Path parameters are positional, query parameters keyword; a JSON body is the first positional argument (a dictionary) and every documented property is also a keyword argument (`eddy.solve_structural(geometry=..., material=...)`); `**extra` passes undocumented keys through unchanged.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.