aialgos 🤖
A beginner-friendly Python library covering the core AI algorithms taught in university courses.
Zero dependencies — pure Python, works everywhere.
pip install aialgos
What's inside?
| Module | Algorithms |
|---|---|
uninformed |
BFS, DFS, DLS, UCS, Bidirectional BFS |
informed |
Greedy Best-First, A* |
adversarial |
Minimax, Alpha-Beta Pruning |
beyond_classical |
Hill Climbing, Steepest-Ascent HC, Simulated Annealing, Local Beam Search |
csp |
Backtracking, Forward Checking, MRV, LCV, Degree Heuristic |
ann |
Feedforward Neural Network (from scratch) |
Quick Start
Uninformed Search (BFS)
from aialgos import bfs
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}
path = bfs(graph, start='A', goal='E')
print(path) # ['A', 'B', 'E']
Informed Search (A*)
from aialgos import a_star
graph = {
'A': [('B', 1), ('C', 4)],
'B': [('D', 5)],
'C': [('D', 1)],
'D': []
}
heuristic = {'A': 4, 'B': 3, 'C': 1, 'D': 0}
path, cost = a_star(graph, 'A', 'D', heuristic)
print(path, cost) # ['A', 'C', 'D'] 5
Adversarial Search (Minimax)
from aialgos import minimax
# Game tree as nested lists (leaf values: positive=MAX wins)
tree = {'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F', 'G'],
'D': 3, 'E': 5, 'F': 2, 'G': 9}
def get_children(node):
v = tree[node]
return v if isinstance(v, list) else []
def evaluate(node):
v = tree[node]
return v if isinstance(v, int) else 0
score = minimax('A', depth=0, is_maximizing=True,
get_children=get_children, evaluate=evaluate, max_depth=2)
print(score) # 5
Neural Network (ANN)
from aialgos import NeuralNetwork
# Solve XOR problem
nn = NeuralNetwork([2, 4, 1], learning_rate=0.1)
X = [[0,0], [0,1], [1,0], [1,1]]
y = [[0], [1], [1], [0]]
nn.train(X, y, epochs=2000, print_every=500)
print(nn.predict([0, 1])) # ≈ [0.95]
print(nn.predict([0, 0])) # ≈ [0.05]
CSP (Map Coloring)
from aialgos import forward_checking
variables = ['WA', 'NT', 'SA', 'Q', 'NSW', 'V']
domains = {v: ['Red', 'Green', 'Blue'] for v in variables}
def diff(a, b): return a != b
constraints_map = {
'WA': [('NT', diff), ('SA', diff)],
'NT': [('WA', diff), ('SA', diff), ('Q', diff)],
'SA': [('WA', diff), ('NT', diff), ('Q', diff), ('NSW', diff), ('V', diff)],
'Q': [('NT', diff), ('SA', diff), ('NSW', diff)],
'NSW': [('Q', diff), ('SA', diff), ('V', diff)],
'V': [('SA', diff), ('NSW', diff)],
}
result = forward_checking(variables, domains, constraints_map)
print(result) # {'WA': 'Red', 'NT': 'Green', 'SA': 'Blue', ...}
Installation
pip install aialgos
Or install from source:
git clone https://github.com/mQasim04/aialgos
cd aialgos
pip install -e .
Similar Libraries
| Library | Focus |
|---|---|
aima3 |
Textbook algorithms (Russell & Norvig) - less beginner-friendly |
networkx |
Graph algorithms only |
python-constraint |
CSP only |
scikit-learn |
ML — no search algorithms |
| aialgos | All-in-one, beginner-focused, zero dependencies |
License
MIT — free to use in education and projects.
Release files for aialgos 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aialgos-0.1.0.tar.gz | 15.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aialgos-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.8 kB
Release files / aialgos-0.1.0.tar.gz
| Download URL | aialgos-0.1.0.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6baf1863eb9b67ead0a4c12fa6d41c595ceae9dc7e389aabb8da295678c5a2c8
|
|
BLAKE2b-256 checksum How to use checksums |
5f7d4f185cef8848871b6175d07616eee8a4ca6070e5a0b2f18b87712c6ed534
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / aialgos-0.1.0-py3-none-any.whl
| Download URL | aialgos-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73b46d1d85be9f457b8ffb4bb4c127202022be5e9dcb31874d0bd438c74574d3
|
|
BLAKE2b-256 checksum How to use checksums |
f4cb484f91cf9e716b52343aef0537794ffede38e86b1bce48bd2a7170edf923
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|