A resilient Python client for the IAEA LiveChart of Nuclides API.
Project description
py-livechart
py-livechart is a resilient Python client for the IAEA LiveChart of Nuclides Data Download API. It wraps requests with thread-safe sessions, retry-aware HTTP adapters, client-side rate limiting, rich exceptions, and optional dataclass models so nuclear engineers can script reproducible pipelines without re-implementing networking boilerplate.
Table of contents
- Installation
- Quick start
- Core API surface
- Robustness and concurrency
- Request limits and performance
- Examples and case studies
- Machine learning helper
- PyPI/CI workflow
- License
Installation
PyPI (recommended)
pip install py-livechart
Optional extras:
pip install "py-livechart[plot]" # plotly, kaleido
pip install "py-livechart[ml]" # scikit-learn
pip install "py-livechart[dev]" # pytest, requests-mock, build
From source
git clone https://github.com/ybtang-prog/py-livechart.git
cd py-livechart
pip install -e .
Quick start
from py_livechart import LiveChartClient
client = LiveChartClient(rate_limit_per_sec=1.0, timeout=20)
ground_states = client.get_ground_states("60co")
fission_records = client.get_fission_yields(
"cumulative_fy", parent="235u", return_type="records"
)
print(ground_states.head())
print(fission_records[0])
Additional, fully reproducible scripts live in example.py, data/, and output/.
Core API surface
| Method | Key parameters | Return | Notes |
|---|---|---|---|
get_ground_states(nuclide, return_type) |
nuclide="60co" or "all" |
DataFrame / GroundStateRecord |
Nuclide ground-state metadata |
get_levels(nuclide, return_type) |
same as above | DataFrame / records | Level schemes |
get_gammas(nuclide, return_type) |
same as above | DataFrame / records | Gamma emissions |
get_decay_rads(nuclide, rad_type, return_type) |
rad_type ∈ {a,bp,bm,g,e,x} |
DataFrame / records | Decay radiation |
get_beta_spectra(nuclide, rad_type, metastable_seqno, return_type) |
rad_type ∈ {bp,bm} |
DataFrame / records | Beta spectra with optional metastable selector |
get_fission_yields(yield_type, parent, product, return_type) |
yield_type ∈ {cumulative_fy, independent_fy} |
DataFrame / FissionYieldRecord |
Parent/product filters |
fetch_ground_states_many(nuclides, return_type, max_workers) |
sequence of nuclides | mapping + error map | Thread-safe concurrent helper |
Each public method has parameter-oriented docstrings, and all custom exceptions are defined in py_livechart/exceptions.py for easy rendering with pdoc, sphinx, or the SoftwareX manuscript.
Robustness and concurrency
- Timeouts + retries: every HTTP call honors a configurable timeout (default 15 s) and attaches
urllib3.Retrywith exponential backoff for 429/5xx codes. - Token-bucket rate limiting: default throttle is 1.5 req/s to satisfy the LiveChart guideline of ≤3 req/s per user. Set
rate_limit_per_sec=0to disable or tuneburst_size. - Thread-safe sessions: each worker thread lazily receives its own
requests.Sessionso researchers can re-use a single client insideThreadPoolExecutor. - Concurrent helper:
fetch_ground_states_manybatches nuclide lists and emits both payloads and per-nuclide errors, which removes boilerplate when building large caches. - Rich error model: the client differentiates invalid parameter payloads, missing inputs, server-side outages, request timeouts, and local throttling, making it clear which failures are actionable.
- Data abstractions:
GroundStateRecordandFissionYieldRecorddecouple downstream code from raw CSV column names, easing cross-library comparisons (ENSDF, JEFF, ENDF/B, etc.).
Request limits and performance
- The IAEA Nuclear Data Section recommends ≤3 requests/s per user. The default limit of 1.5 req/s proved reliable for day-to-day scripted work and for HPC queues.
- Shanghai 100 Mbps lab measurements (Nov 2025):
get_ground_states("60co"): median 0.34 s (n=30)get_ground_states("all"): ~95 s at 1 req/s, suitable for nightly jobs or cached mirrorsget_fission_yields("cumulative_fy","235u"): ~0.78 s (n=20)
- Additional benchmarks, including throughput vs. rate-limit settings, are documented in
docs/case_studies.mdfor direct citation inside the SoftwareX manuscript.
Examples and case studies
example.py contains four runnable workflows with logging and exception handling:
- Thread-safe batch fetch – uses
fetch_ground_states_manyto download multiple nuclides in parallel and reports individual failures. - Ground-state query – prints the full Co‑60 table and demonstrates the
return_type="records"abstraction. - Fission yield analysis – generates
output/u235_fission_yield.pdfwith Plotly, and compares IAEA yields against thedata/jeff_fission_yield_sample.csvexcerpt. - Machine learning template – calls
ml.train_half_life_modelandml.predict_half_life_secondsto showcase a reproducible data-mining workflow.
Expanded commentary, reproducibility notes, and links to figures referenced in the manuscript are compiled in docs/case_studies.md.
To keep tests deterministic while still relying on real physics data, run python scripts/cache_ground_states.py. This helper downloads the entire ground-state catalog (nuclides=all) from the official LiveChart API (using the recommended User-Agent header) and stores the snapshot in data/ground_states_sample.csv (~3.3k rows). The ML unit test consumes this real snapshot so reviewers can reproduce the workflow without synthetic fixtures.
Machine learning helper
The optional py_livechart.ml module packages a safe baseline for researchers who want to perform rapid prototyping:
train_half_life_modelstandardizes numeric columns, removes non-physical targets, and trains aSimpleImputer + RandomForestRegressorpipeline with deterministic seeds.- The function returns
(model, metrics, features)wheremetricscontainsr2_score,rmsle, andmale. Negativer2values trigger a warning so users know the proxy model should not be deployed as-is. predict_half_life_secondsenforces feature order, performs the same numeric cleanup, fills any missing data prior to inference, and returns physical half-life values in seconds.
from py_livechart import LiveChartClient, ml
client = LiveChartClient()
model, metrics, features = ml.train_half_life_model(client)
print(metrics)
ca48 = client.get_ground_states("48ca")
prediction = ml.predict_half_life_seconds(model, features, ca48)
print(f"T1/2(Ca-48) ≈ {prediction:.3e} s")
PyPI/CI workflow
.github/workflows/publish.ymlruns linting andpyteston pushes and pull requests. When a tag matchingv*is pushed, it builds wheels + source distributions and uploads them withPYPI_API_TOKEN.- Manual release commands:
python -m build
twine upload dist/*
License
MIT. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_livechart-1.2.0.tar.gz.
File metadata
- Download URL: py_livechart-1.2.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df6c66a0b6834a6e1b660a227cfe0d0d42d301c44bd716959e931adfe04cb5fc
|
|
| MD5 |
e3ef8bab96055f111febeb4b878b87d2
|
|
| BLAKE2b-256 |
4de4593473222de6027e4521083516567d6487fe1aa10cd956000f482466879c
|
File details
Details for the file py_livechart-1.2.0-py3-none-any.whl.
File metadata
- Download URL: py_livechart-1.2.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32578f37cbf814c465b312f9e243b74b006d976025e0593dde00d0d2fcb59207
|
|
| MD5 |
0a7780e2e91d126e3ae91aee565bd7da
|
|
| BLAKE2b-256 |
1cad20f38c09a8fabb9993456130c8318f95700c0099ae5d4712a10e26e17296
|