skillfed

pygad

PyGAD: A Python Library for Building the Genetic Algorithm and Training Machine Learning Algoithms (Keras & PyTorch).

pygad v3.7.0 90.1K downloads/30d#13,617 on PyPI2,220
License unclear 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) Active released

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 pygad

uv

uv add pygad

poetry

poetry add pygad

Installing 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

Intended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: Information TechnologyIntended Audience :: Other AudienceIntended Audience :: Science/ResearchNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Scientific/Engineering :: Bio-InformaticsTopic :: Software DevelopmentTopic :: Utilities

Tags

genetic algorithm pythonevolutionary optimization libraryneural network training optimizationmulti-objective optimizationmachine learning hyperparameter tuninggenetic algorithm keras pytorchpopulation-based optimization
evolutionary-computationhyperparameter-optimizationneural-network-training

More Software Development packages