pyswarms
A Python-based Particle Swarm Optimization (PSO) library.
What it is and what it does
PySwarms is a research toolkit for particle swarm optimization (PSO) that provides ready-to-use implementations of PSO algorithms alongside utilities for hyperparameter tuning, visualization, and testing. It wraps scipy, numpy, and matplotlib to deliver a declarative interface where you define an objective function, configure swarm parameters, and run the optimizer to find minima or maxima across your problem space.
The package targets researchers, students, and practitioners who want to apply PSO without building the algorithm from scratch. It includes built-in test functions, grid and random search tools for hyperparameter optimization, and plotting utilities to visualize cost histories and particle trajectories. The API is extensible, allowing researchers to implement custom PSO variants. Dependencies are standard scientific Python libraries (scipy, numpy, matplotlib, attrs, tqdm, pyyaml, future), making it straightforward to integrate into existing workflows.
Use it for:
- Solve unconstrained continuous optimization problems where gradient-free metaheuristic search is preferred over calculus-based methods.
- Tune hyperparameters of a PSO optimizer using built-in grid or random search to find the best configuration for your objective function.
- Visualize swarm behavior and cost convergence over iterations using the plotting module to understand optimizer performance and debug tuning choices.
- Implement custom PSO variants or hybrid algorithms by extending the toolkit's base classes for research publications or specialized applications.
- Benchmark PSO against other metaheuristics on standard test functions provided in the utils module.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PySwarms implements particle swarm optimization (PSO) algorithms in Python, providing a high-level interface for solving optimization problems using swarm intelligence techniques.
Yes, if you are doing research, education, or prototyping with particle swarm optimization. The low install friction, permissive MIT license, and extensible design make it a solid choice for PSO work. However, be aware that the package is dormant—the latest release is from 2021-01-03, so compatibility with very recent Python or dependency versions is uncertain. Not recommended for production systems requiring active maintenance and support.
Install
pyswarms on PyPI
pip
pip install pyswarmsuv
uv add pyswarmspoetry
poetry add pyswarmsInstalling pyswarms
Before you install
Low install friction with a pure-Python wheel distribution. Maintenance is dormant—the latest release was 2021-01-03, though the repository remains active with a recent commit on 2024-08-06 and 1393 stars. Suitable for research and educational use but not actively developed.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution. Safe for commercial and open-source projects alike.
Quickstart
pip install pyswarms
import pyswarms as ps
from pyswarms.utils.functions import single_obj as fx
options = {'c1': 0.5, 'c2': 0.3, 'w': 0.9}
optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options)
best_cost, best_pos = optimizer.optimize(fx.sphere, iters=100)
Verify before relying
- Whether the package works reliably with Python versions beyond 3.7 (classifiers list only 3.6 and 3.7 explicitly)
- Current compatibility with modern scipy and numpy versions given dormant maintenance status since 2021-01-03
Package facts
| License | MIT license (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — scipy, numpy, matplotlib, attrs, tqdm, future, pyyaml |
| Maintenance | dormant — 2,049 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 74,825/month — #14,788 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyswarms-1.3.0-py2.py3-none-any.whl
Keywords: pyswarms
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
pytorch_optimizerProvides a collection of modern optimizers,…
permissive · top 15,000 on PyPI
deapDEAP is an evolutionary computation framework…
copyleft · top 15,000 on PyPI
cmaesProvides CMA-ES (Covariance Matrix Adaptation…
permissive · top 5,000 on PyPI
pymoopymoo implements single- and multi-objective…
permissive · top 5,000 on PyPI
scikit-fuzzyscikit-fuzzy provides fuzzy logic algorithms…
unclear · top 15,000 on PyPI
optaxOptax provides composable building blocks for…
permissive · top 5,000 on PyPI
pyomoPyomo is a Python framework for formulating and…
permissive · top 5,000 on PyPI
torch-optimizerProvides a collection of alternative…
permissive · top 15,000 on PyPI
docplexModeling library for building and solving…
permissive · top 15,000 on PyPI
dopamine-rlDopamine is a research framework for…
permissive · top 15,000 on PyPI