skillfed

logical-unification

Logical unification in Python

logical-unification v0.4.7 1.3M downloads/30d#4,133 on PyPI53
Permissive license BSD-3-Clause Active released

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-unification

uv

uv add logical-unification

poetry

poetry add logical-unification

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries

Tags

logical unification pattern matchingunify variables in data structureslogic programming pythonpattern matching dispatchunification reificationlogic variable bindingsymbolic pattern matching
logic-programmingpattern-matchingsymbolic-computation

More Libraries packages