Skip to main content
GALib logo

GALib

CI Coverage PyPI License: Apache 2.0

A small, extensible library to build genetic algorithms in Python 3.10+. Fully typed, no dependencies in the core, optional numpy acceleration.

Documentation: https://carmelolg.github.io/GALib/

Distribution name (pip install) carmelolg-galib
Import name carmelolg.galib

carmelolg is a PEP 420 namespace package.

Quick start

import string
from carmelolg.galib import GeneticAlgorithm, Problem, TargetFitness

TARGET = "hello world"
ALPHABET = string.ascii_lowercase + " "


class Phrase(Problem[str]):
    def random_genome(self, rng):  # one random candidate
        return "".join(rng.choice(ALPHABET) for _ in TARGET)

    def random_gene(self, rng):  # enables the default mutation
        return rng.choice(ALPHABET)

    def fitness(self, genome):  # higher is better (set `maximize = False` to minimise)
        return sum(a == b for a, b in zip(genome, TARGET))


result = GeneticAlgorithm(Phrase(), stop=[TargetFitness(len(TARGET))], seed=1).run()
print(result.best.genome)  # hello world

Features

  • Three levels of customisation: parameters; pluggable operators (any callable, or methods on your Problem); subclasses of the engine overriding select, crossover, mutate, reproduce, replace, ...
  • Operators for sequences (OnePoint, TwoPoint, Uniform, RandomReset), permutations (OrderCrossover, PartiallyMappedCrossover, SwapMutation, InversionMutation) and real values (BlendCrossover, GaussianMutation); selection by Tournament, Roulette, Rank.
  • Monitoring: per-generation statistics and diversity, callbacks (PrintProgress), stop conditions (TargetFitness, Stagnation, TimeLimit), plots.
  • Performance: vectorised fitness_batch, numpy array genomes, parallel evaluation in chunks (workers=N, or any executor).
  • Reproducible: each run has its own seeded random generator.

Built with GALib

  • GAPoly evolves polygons, discs, Voronoi cells, tiles, glyphs or brush strokes until they look like a target photo (source).

Development

python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,docs]"

python -m pytest --cov                     # tests with branch coverage
mypy                                       # strict type checking
ruff check src tests examples benchmarks   # lint
mkdocs serve                               # documentation preview on http://127.0.0.1:8000
python examples/tsp.py                     # examples: phrase, knapsack, tsp, rastrigin

The documentation sources are in docs/ (MkDocs Material); .github/workflows/docs.yml publishes them to GitHub Pages, .github/workflows/ci.yml runs tests, types, lint and the docs build.

License

Copyright 2026 CARMELO LA GAMBA. Licensed under the Apache License, Version 2.0. Redistributions must keep the copyright notices and include the NOTICE file.

Metadata

Release files for carmelolg-galib 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for carmelolg-galib 0.3.3
File Size Uploaded Provenance Actions
carmelolg_galib-0.3.3.tar.gz 37.7 kB With provenance Details for carmelolg_galib-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for carmelolg-galib 0.3.3
File Interpreter ABI Platform Actions
carmelolg_galib-0.3.3-py3-none-any.whl Python 3 none any Details for carmelolg_galib-0.3.3-py3-none-any.whl

Total release size: 70.3 kB

Release files / carmelolg_galib-0.3.3.tar.gz

Download URL carmelolg_galib-0.3.3.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d6e954455676362be3e5feca2503a3caf37a73fc32b4cea28ef6101c1999fc11
BLAKE2b-256 checksum
How to use checksums
72c50609a2cfa4a5e48a22ffe8ee4227b8213ac0771c77748a69482c9256f002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / carmelolg_galib-0.3.3-py3-none-any.whl

Download URL carmelolg_galib-0.3.3-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93be81b1e2fecb965b5b8ad33a8fbb0887f731619b1a04f6aa2871444fd4d22d
BLAKE2b-256 checksum
How to use checksums
b426c15bb5cbb0e0bc86d00cb1ef8110c0849666ed2b6e2d61a913f62e528cc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for carmelolg-galib 0.3.3

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for carmelolg_galib-0.3.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page