optuna
A hyperparameter optimization framework
What it is and what it does
Optuna is a framework for automating hyperparameter optimization in machine learning. It uses a define-by-run API where you write an objective function that suggests hyperparameter values and returns a metric to minimize or maximize; Optuna then orchestrates multiple trials to find the best configuration. The framework supports dynamic search spaces (conditionals and loops), efficient sampling algorithms including pruning of unpromising trials, and easy parallelization across workers.
The package is designed for practitioners who need to tune models systematically without manually scripting grid or random search. It integrates with popular ML libraries (scikit-learn, PyTorch, TensorFlow, XGBoost, LightGBM, and others) and provides visualization tools to inspect optimization history. Storage is pluggable (SQLite, PostgreSQL, etc. via SQLAlchemy), making it suitable for both single-machine experiments and distributed optimization studies.
Use it for:
- Tune scikit-learn model hyperparameters (e.g., SVM regularization, random forest depth) by defining an objective function that trains and evaluates the model.
- Optimize neural network architectures and training hyperparameters in PyTorch or TensorFlow with pruning to stop unpromising trials early.
- Run multi-objective optimization to balance competing goals (e.g., model accuracy vs. inference latency) across multiple workers.
- Store and visualize optimization histories in a persistent database for reproducibility and post-hoc analysis via the Optuna Dashboard.
- Implement constrained optimization where hyperparameter choices depend on earlier trial results using conditional suggest calls.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Optuna is a hyperparameter optimization framework that automates the search for optimal hyperparameter values in machine learning models using a define-by-run API and state-of-the-art sampling algorithms.
Yes. Optuna is a mature, actively maintained framework (Production/Stable, 14662 stars, recent releases) with low install friction, no known vulnerabilities, and permissive MIT licensing. It is well-suited for anyone doing systematic hyperparameter tuning in machine learning and offers a more flexible, Pythonic alternative to grid or random search.
Install
optuna on PyPI
pip
pip install optunauv
uv add optunapoetry
poetry add optunaInstalling optuna
Before you install
Low install friction with a pure-Python wheel and seven common runtime dependencies (alembic, colorlog, numpy, packaging, sqlalchemy, tqdm, PyYAML). Actively maintained with a recent release 74 days ago and 14662 repository stars.
License in practice
Licensed under MIT (permissive), allowing unrestricted use, modification, and distribution in both open-source and commercial projects.
Quickstart
pip install optuna
import optuna
def objective(trial):
x = trial.suggest_float('x', -10, 10)
return x**2
study = optuna.create_study()
study.optimize(objective, n_trials=100)
Requires Python 3.9 or newer.
Verify before relying
- Whether the package's distributed optimization scales to 'tens or hundreds of workers' as claimed without additional infrastructure setup.
- Performance characteristics and convergence speed compared to other hyperparameter optimization frameworks in typical ML workflows.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — alembic, colorlog, numpy, packaging, sqlalchemy, tqdm, PyYAML |
| Maintenance | actively maintained — 74 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 17,394,263/month — #1,121 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: optuna-4.9.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
hydra-optuna-sweeperIntegrates Optuna hyperparameter optimization…
permissive · top 15,000 on PyPI
hyperoptHyperopt performs serial and parallel…
permissive · top 5,000 on PyPI
keras-tunerKerasTuner automates hyperparameter…
permissive · top 15,000 on PyPI
optuna-dashboardProvides a real-time web dashboard for…
permissive · top 15,000 on PyPI
optuna-integrationProvides integration modules connecting Optuna…
permissive · top 5,000 on PyPI
cmaesProvides CMA-ES (Covariance Matrix Adaptation…
permissive · top 5,000 on PyPI
ConfigSpaceConfigSpace defines and manipulates…
permissive · top 15,000 on PyPI
moocoreProvides fast implementations of core…
copyleft · top 5,000 on PyPI
pyannote-pipelineDefines and optimizes tunable hyperparameter…
unclear · top 5,000 on PyPI
FLAMLFLAML automates machine learning workflows by…
permissive · top 15,000 on PyPI