py-typedlogic: Pythonic logic for your data models.
Define logical predicates directly in Python as Pydantic, dataclasses, SQLModel, or plain python objects:
# links.py
from pydantic import BaseModel
from typedlogic import FactMixin, Term
ID = str
class Link(BaseModel, FactMixin):
"""A link between two entities"""
source: ID
target: ID
class Path(BaseModel, FactMixin):
"""An N-hop path between two entities, consisting of one or more links"""
source: ID
target: ID
hops: int
This data model has two classes, Link and Path. These also correspond to predicate signatures
in a logical theory.
You can use this to create objects (ground terms, in logic terms) using normal Python code:
links = []
for source, target in [('CA', 'OR'), ('OR', 'WA')]:
links.append(link)
Define logical constraints or rules using Python syntax:
from typedlogic.decorators import axiom
@axiom
def path_from_link(x: ID, y: ID):
"""If there is a link from x to y, there is a path from x to y"""
if Link(source=x, target=y):
assert Path(source=x, target=y, hops=1)
@axiom
def transitivity(x: ID, y: ID, z: ID, d1: int, d2: int):
"""Transitivity of paths, plus hop counting"""
if Path(source=x, target=y, hops=d1) and Path(source=y, target=z, hops=d2):
assert Path(source=x, target=z, hops=d1+d2)
Use a solver to infer new facts:
from typedlogic.registry import get_solver
from links import Link
solver = get_solver("clingo")
solver.load(links)
links = [Link(source='CA', target='OR'), Link(source='OR', target='WA')]
for link in links:
solver.add(link)
model = solver.model()
for fact in model.iter_retrieve("Path"):
print(fact)
prints:
Path(source='CA', target='OR')
Path(source='OR', target='WA')
Path(source='CA', target='WA')
Key Features
- Write logical axioms and rules using Python syntax
- Interconvert between different logical formats and formalisms
- Benefit from strong typing and mypy validation
- Integration with multiple FOL solvers and logic programming engines
- Integration with OWL-DL
- Integration with Python libraries like Pydantic
- Command Line and Python interfaces
Installation
Install TypedLogic using pip:
pip install "typedlogic"
Next Steps
- Consult the main docs for more information
Contributing
Testing with External Dependencies
Some tests require external executables (Prover9, Souffle) that may not be available in all environments. The test suite is designed to automatically skip tests that require unavailable dependencies.
When running in CI environments:
- Tests for external solvers are automatically skipped if the dependency is not available
- This allows CI to pass while still testing all available functionality
To install optional dependencies for testing:
- Prover9: Install from your package manager or from source
- Souffle: Install from your package manager or from source
Run tests with:
uv run pytest
Release files for typedlogic 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typedlogic-0.2.4.tar.gz | 953.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typedlogic-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / typedlogic-0.2.4.tar.gz
| Download URL | typedlogic-0.2.4.tar.gz |
|---|---|
| Size | 953.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6f3c6b6302f0a317ae7e79a5dc23b7d220268b6f2247eb665e94e2144f685df
|
|
BLAKE2b-256 checksum How to use checksums |
9d26bc5617b61f64188509c3015ef6fb1071033f7aa9e58504da6090cdd054e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / typedlogic-0.2.4-py3-none-any.whl
| Download URL | typedlogic-0.2.4-py3-none-any.whl |
|---|---|
| Size | 222.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
399fe02e65105d1b025cbad705268f96e1e699e9c88ff199deb8471c65ff047a
|
|
BLAKE2b-256 checksum How to use checksums |
6e648933de82e14e2a2ac20bf959095fb3221c88c8cefe1341a0c5dd786ad7a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency log