skillfed

pyswarms

A Python-based Particle Swarm Optimization (PSO) library.

pyswarms v1.3.0 74.8K downloads/30d#14,788 on PyPI1,393
Permissive license MIT license DORMANT released

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 pyswarms

uv

uv add pyswarms

poetry

poetry add pyswarms

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishProgramming Language :: Python :: 3.6Programming Language :: Python :: 3.7Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Mathematics

Tags

particle swarm optimizationPSO algorithm implementationswarm intelligence optimizationmetaheuristic optimization libraryhyperparameter optimization searchoptimization algorithm toolkitnumerical optimization python
metaheuristic-optimizationresearch-toolkitswarm-intelligence

More Scientific/Engineering packages