Metadata-Version: 2.4
Name: feconfig
Version: 0.1.0
Summary: Python client for the feconfig filter-configuration service (LIGO front-end filters)
Author: Erik von Reis
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://git.ligo.org/erik.vonreis/feconfig
Project-URL: Source, https://git.ligo.org/erik.vonreis/feconfig
Keywords: ligo,cds,foton,filters,epics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: COPYING
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# feconfig Python client

A small client for the feconfig JSON API, with no dependencies beyond the
standard library. Foton's Python wrapper (`foton.py` in dtt) uses it to
check out modules from feconfig and submit them back; scripts can use it
directly.

```python
import feconfig

c = feconfig.Client()                 # server and token from the environment or config files
for m in c.models():
    print(m["name"], m["host"])
co = c.checkout("X2SUSOM0/OM0_M3_COILOUTF_LL")
text = co["text"]                      # foton file text for that module
# ... edit the text, or build a foton.FilterFile from it ...
r = c.submit(text, "notch the 1 Hz line", model="X2SUSOM0")
print(r["batch_id"], [f"{x['module']}/FM{x['fm']}" for x in r["changes"]])
```

## Server and credentials

`Client(server=None, token=None)` looks, in order, at the arguments, the
environment (`FECONFIG_SERVER`, `FECONFIG_TOKEN`), the user's
`~/.config/feconfig/credentials.toml` written by `feconfig-cli login`, and
the site file `/etc/feconfig/client.toml` (`server = "http://host:8080"`).
`Client.login(server, user, password)` exchanges a password for a token
and can save it to the credentials file.

Errors from the server raise `feconfig.FeconfigError` with `.status`,
`.code` (such as `forbidden`, `unloaded_edits`, `filters_on`,
`epics_disabled`) and `.message`.

## Testing

`pytest` here starts a feconfig server from `target/debug/feconfig` (build
it first with `cargo build -p feconfig`) on a free port with a temporary
tree and the static auth backend, and drives it through the client.
