cons
An implementation of Lisp/Scheme-like cons in Python.
What it is and what it does
The cons package brings Lisp and Scheme's classic cons-cell operations into Python, letting you build and decompose sequences using car (head), cdr (tail), and cons (prepend) functions. It works across Python's standard sequence types—lists, tuples, iterators, and OrderedDicts—while treating None as the empty list, following Scheme conventions. The package also integrates with the logical-unification library, enabling pattern matching and unification on cons structures.
It's designed for developers working with functional programming patterns or symbolic computation in Python. The implementation respects Python's sequence semantics while staying true to Lisp/Scheme behavior; for example, calling car or cdr on an empty sequence raises ConsError rather than returning nil. You can customize which types participate in cons operations by registering them with the MaybeCons and NonCons abstract base classes.
Use it for:
- Build functional data structures using cons pairs in symbolic or logic programming applications.
- Perform pattern matching and unification on Python sequences using the unification integration.
- Implement recursive list algorithms that rely on car/cdr decomposition in a Lisp-like style.
- Work with OrderedDicts and other sequence types using uniform cons semantics.
- Prototype or port Scheme/Lisp algorithms to Python while preserving their list-manipulation idioms.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements Lisp/Scheme-style cons operations (cons, car, cdr) for Python sequences, enabling functional list manipulation across lists, tuples, iterators, and OrderedDicts.
Yes, if you need Lisp/Scheme-style cons operations for functional programming or symbolic computation. Install friction is minimal and maintenance is active. However, verify the license terms first—the license status is unclear and must be confirmed before use in proprietary or copyleft-sensitive contexts.
Install
cons on PyPI
pip
pip install consuv
uv add conspoetry
poetry add consInstalling cons
Before you install
Low install friction with a single pure-Python dependency (logical-unification). Actively maintained with recent commits and a stable release cycle; marked Alpha but supports current Python versions (3.9+).
License in practice
License status is unclear—no SPDX identifier or raw license text is available. Verify the actual license terms before using in proprietary or copyleft-sensitive projects.
Quickstart
pip install cons
from cons import cons, car, cdr
result = cons(1, [2, 3])
print(result) # [1, 2, 3]
print(car(result)) # 1
print(cdr(result)) # [2, 3]
Requires Python 3.9 or later.
Verify before relying
- Whether the unclear license permits use in closed-source or commercial projects.
- Performance characteristics when working with very large sequences or deeply nested cons operations.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — logical-unification |
| Maintenance | actively maintained — 399 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,277,357/month — #4,123 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cons-0.4.7-py3-none-any.whl
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
snuggsSnuggs evaluates s-expressions (Lisp-like…
permissive · top 15,000 on PyPI
logical-unificationLogical unification in Python with support for…
permissive · top 5,000 on PyPI
funcyFuncy provides a collection of functional…
permissive · top 5,000 on PyPI
pampyPampy provides pattern matching for Python,…
permissive · top 15,000 on PyPI
pipePipe enables shell-like infix syntax for…
permissive · top 15,000 on PyPI
ordereddictProvides an OrderedDict implementation for…
permissive · top 15,000 on PyPI
infinityProvides an Infinity class that can be compared…
permissive · top 15,000 on PyPI
funcparserlibFuncparserlib is a recursive descent parsing…
permissive · top 15,000 on PyPI
ExpressionExpression provides functional programming…
permissive · top 5,000 on PyPI
etuplesProvides S-expression emulation using…
permissive · top 5,000 on PyPI