jsonify-optuna
Convert an Optuna Study into a plain, JSON-serializable Python dict.
Installation
pip install jsonify-optuna
Usage
Convert an in-memory study to a JSON-friendly dict:
import optuna
from jsonify_optuna import jsonify
from optuna.trial import TrialState
def objective(trial):
x = trial.suggest_float("x", -10.0, 10.0)
return x ** 2
study = optuna.create_study(direction="minimize")
study.optimize(objective, n_trials=20)
result = jsonify(study, states=[TrialState.COMPLETE])
# This includes all the trials.
result = jsonify(study)
Reconstruct an optuna.Study from a JSON dict:
from jsonify_optuna import json_to_optuna_study
study = json_to_optuna_study(result)
If you have a study stored in a backend, you can load it as follows:
from jsonify_optuna import load_study
# From an RDB (SQLite, PostgreSQL, etc.)
study = load_study(rdb_url="sqlite:///example.db", study_name="my_study")
# From a journal file
study = load_study(journal_path="journal.log", study_name="my_study")
# From a storage object directly
study = load_study(storage=my_storage, study_name="my_study")
API Reference
jsonify(study, *, states=None, deepcopy=True)
| Parameter | Type | Description |
|---|---|---|
study |
optuna.Study |
The study to convert. |
states |
list[TrialState] | None |
Filter trials by state. None includes all states. |
deepcopy |
bool |
Whether to deep-copy trials from storage. Default True. |
Returns a dict with:
| Key | Type | Description |
|---|---|---|
directions |
list[str] |
"minimize" or "maximize" per objective. |
user_attrs |
dict |
Study-level user attributes. |
metric_names |
list[str] | None |
Metric names if set, else None. |
trials |
list[dict] |
Trial dicts (see below). |
best_trial_indices |
list[int] |
Indices into trials for Pareto-front trials. |
Each trial dict contains:
| Key | Type | Description |
|---|---|---|
state |
str |
"complete", "pruned", "fail", "running", or "waiting". |
values |
list[float] | None |
Objective values. None if not complete. |
params |
dict |
Parameter name-value pairs. |
user_attrs |
dict |
Trial-level user attributes. |
intermediate_values |
dict[int, float] |
Step-value pairs from trial.report(). |
distributions |
dict |
Parameter distributions (see below). |
Distribution formats:
- Int/Float:
{"low": ..., "high": ..., "step": ..., "log": ...} - Categorical:
{"choices": [...]}
json_to_optuna_study(study_json)
| Parameter | Type | Description |
|---|---|---|
study_json |
StudyType |
A dict produced by jsonify(). |
Returns an in-memory optuna.Study with directions, user attributes, metric names, and all trials reconstructed from the JSON dict.
load_study(*, study_name=None, storage=None, journal_path=None, rdb_url=None)
| Parameter | Type | Description |
|---|---|---|
study_name |
str | None |
Study name. Optional when storage has exactly one study. |
storage |
BaseStorage | None |
An Optuna storage object. |
journal_path |
str | None |
Path to a journal log file. |
rdb_url |
str | None |
SQLAlchemy-style database URL. |
Exactly one of storage, journal_path, or rdb_url must be provided.
Metadata
Release files for jsonify-optuna 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jsonify_optuna-0.4.0.tar.gz | 93.2 kB | Without provenance | Details for jsonify_optuna-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jsonify_optuna-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for jsonify_optuna-0.4.0-py3-none-any.whl |
Total release size: 98.0 kB
Release files / jsonify_optuna-0.4.0.tar.gz
| Download URL | jsonify_optuna-0.4.0.tar.gz |
|---|---|
| Size | 93.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38e77a1934af4f941732844af4305926acce0e65b6b859d94e38f42898d0ca89
|
|
BLAKE2b-256 checksum How to use checksums |
df35241ac8472187864e77796802f9ca7dda81c197135a129d623c2aef468d6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / jsonify_optuna-0.4.0-py3-none-any.whl
| Download URL | jsonify_optuna-0.4.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b8cca8c90deb4e244ef301ffa2495456232d374b8de397bb9eb177153b6ee54
|
|
BLAKE2b-256 checksum How to use checksums |
be737131d432d247c47d10eb823dffadb4c4feacbcb6e7e6289aa366d0ece391
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for jsonify-optuna 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.