pygad
PyGAD: A Python Library for Building the Genetic Algorithm and Training Machine Learning Algoithms (Keras & PyTorch).
What it is and what it does
PyGAD is a genetic algorithm library that lets you define a fitness function and run an evolutionary optimization loop to find good solutions to single- or multi-objective problems. It handles population initialization, parent selection, crossover, and mutation automatically, with callback hooks at each stage so you can monitor or intervene in the algorithm's execution. The core library depends only on numpy and cloudpickle, keeping the base install lightweight; optional extras add visualization (matplotlib) and deep learning integration (Keras/PyTorch).
You write a fitness function that scores candidate solutions, then instantiate a GA object with your parameters (population size, number of generations, crossover/mutation strategy) and call run(). The library is actively maintained, supports current Python versions, and is documented with examples covering both simple optimization problems and neural network training scenarios.
Use it for:
- Optimize weights or hyperparameters for a machine learning model when gradient-based methods are impractical or you want to explore a non-convex search space.
- Train neural network weights using Keras or PyTorch by wrapping the model in a fitness function that evaluates test accuracy.
- Solve combinatorial or discrete optimization problems (e.g., scheduling, routing) where you define fitness as a penalty-based score.
- Multi-objective optimization where you balance competing goals (e.g., model accuracy vs. inference speed) in a single fitness metric.
- Educational exploration of genetic algorithms and evolutionary computation with built-in lifecycle callbacks to trace algorithm behavior.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PyGAD is a Python library for building and running genetic algorithms to optimize single-objective and multi-objective problems, with built-in support for training Keras and PyTorch models.
Yes. PyGAD is actively maintained, has low install friction, no known vulnerabilities, and a clear use case for evolutionary optimization and neural network training. The BSD 3-Clause license is permissive. Install it if you need genetic algorithm optimization; skip it if you only do gradient-based machine learning. Verify the license treatment classification if your use case has strict licensing requirements.
Install
pygad on PyPI
pip
pip install pygaduv
uv add pygadpoetry
poetry add pygadInstalling pygad
Before you install
Low install friction with only two runtime dependencies (numpy and cloudpickle). Active maintenance with recent releases; last commit 2026-07-09. Optional extras available for visualization and deep learning features.
License in practice
Licensed under BSD 3-Clause, which permits commercial and private use with attribution and liability disclaimers. License treatment is marked unclear in the fact sheet, so verify the exact terms apply to your use case.
Quickstart
pip install pygad
import pygad
import numpy
def fitness_func(ga_instance, solution, solution_idx):
output = numpy.sum(solution * [4, -2, 3.5, 5, -11, -4.7])
return 1.0 / (numpy.abs(output - 44) + 0.000001)
ga = pygad.GA(num_generations=100, num_parents_mating=7,
fitness_func=fitness_func, sol_per_pop=10, num_genes=6)
ga.run()
Verify before relying
- Whether license_treatment 'unclear' indicates any actual licensing ambiguity or is a data classification artifact
- Performance characteristics and scalability limits for large population sizes or high-dimensional problems
- Availability and stability of optional extras (visualize, deep_learning) across Python versions
Package facts
| License | Copyright GeneticAlgorithmPython Contributors Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1.… (full text in the JSON record) (unclear) |
| Python support | supports the current Python release (>=3) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — numpy, cloudpickle |
| Maintenance | actively maintained — 70 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 90,134/month — #13,617 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pygad-3.7.0-py3-none-any.whl
Keywords: genetic algorithm, GA, optimization, evolutionary algorithm, natural evolution, pygad, machine learning, deep learning, neural networks, tensorflow, keras, pytorch
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
deapDEAP is an evolutionary computation framework…
copyleft · top 15,000 on PyPI
pymoopymoo implements single- and multi-objective…
permissive · top 5,000 on PyPI
keras-tunerKerasTuner automates hyperparameter…
permissive · top 15,000 on PyPI
amalgam-langAmalgam is a Python wrapper that lets you call…
agpl · top 15,000 on PyPI
moocoreProvides fast implementations of core…
copyleft · top 5,000 on PyPI
tensorflow-model-optimizationProvides quantization, pruning, and clustering…
permissive · top 15,000 on PyPI
optlangOptlang formulates and solves linear,…
permissive · top 15,000 on PyPI
pyomoPyomo is a Python framework for formulating and…
permissive · top 5,000 on PyPI
optuna-integrationProvides integration modules connecting Optuna…
permissive · top 5,000 on PyPI
kerasKeras 3 is a multi-backend deep learning…
permissive · top 5,000 on PyPI