logical-unification
Logical unification in Python
What it is and what it does
Logical unification is a computer science technique for finding substitutions that make different terms equivalent. This package implements unification in Python, allowing you to match patterns against data structures and extract variable bindings. It supports built-in Python types (tuples, dicts, namedtuples) and can be extended to custom classes via the @unifiable decorator.
The package also provides pattern-matching dispatch, letting you define multiple function implementations that are selected based on pattern matching against arguments. It uses a generator-based design to handle deeply nested structures without hitting Python's recursion limit, making it suitable for symbolic computation, logic programming, and complex pattern-based control flow.
Use it for:
- Extract values from nested data structures using pattern matching with logic variables instead of manual traversal.
- Implement logic-programming-style algorithms like recursive pattern matching (e.g., Fibonacci via pattern dispatch).
- Route or dispatch function calls based on complex structural patterns in dictionaries or custom objects.
- Unify and reify custom domain objects (e.g., Account records) to find matching instances or extract fields.
- Build symbolic computation systems where you need to reason about term equivalence and substitution.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Logical unification in Python with support for pattern matching and custom data types, extensible via dispatch on toolz and multipledispatch.
Yes. The package is actively maintained, has no known vulnerabilities, installs with low friction, and offers a unique capability for pattern matching and logical unification that is not easily replicated with standard Python. It is well-suited for logic programming, symbolic computation, and complex pattern-based dispatch. The BSD-3-Clause license is permissive and poses no barrier.
Install
logical-unification on PyPI
pip
pip install logical-unificationuv
uv add logical-unificationpoetry
poetry add logical-unificationInstalling logical-unification
Before you install
Low install friction with a pure Python wheel and only two lightweight runtime dependencies. Active maintenance with a recent commit on 2026-02-25 and stable production status.
License in practice
BSD-3-Clause permissive license allows use in most projects, including commercial, with minimal restrictions beyond attribution.
Quickstart
pip install logical-unification
from unification import var, unify, reify
x = var()
result = unify((1, x), (1, 2))
print(result) # {~x: 2}
print(reify((1, x), {x: 2})) # (1, 2)
Requires Python 3.9 or later.
Verify before relying
- Whether the package is actively maintained beyond the latest release date (2025-10-20); last commit is 2026-02-25 but days_since_release is 298.
- Performance characteristics for very large unification problems beyond the benchmarked nested list scenarios.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — toolz, multipledispatch |
| Maintenance | actively maintained — 298 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,268,792/month — #4,133 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: logical_unification-0.4.7-py3-none-any.whl
Keywords: unification, logic-programming, dispatch
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
orderingsProvides an Ordering enumeration and Compare…
permissive · top 15,000 on PyPI
dep-logicPerforms logical operations (AND, OR) on PEP…
permissive · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
consImplements Lisp/Scheme-style cons operations…
unclear · top 5,000 on PyPI
multipledispatchEnables functions to dispatch on the types of…
permissive · top 5,000 on PyPI
json-logicParses and executes JsonLogic rules—a…
permissive · top 5,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
fastuuidFastUUID provides CPython bindings to Rust's…
permissive · top 1,000 on PyPI
classesImplements typeclasses for Python, enabling…
permissive · top 15,000 on PyPI