pcarbonn/pyDatalog
a datalog implementation in Python
What it solves
pyDatalog adds the logic programming paradigm to Python. It lets you write queries over databases and Python objects using Datalog, a declarative language that is more expressive than SQL and supports recursion, which SQL can't do easily. This helps with complex data relationships, recursive algorithms, and constraint problems.
How it works
You install pyDatalog via pip or uv. It provides pre-compiled wheels for most platforms but also has a pure Python fallback that runs anywhere without a C compiler. You define logic clauses in Python, and pyDatalog can execute them against various data sources, including in-memory datastores, 11 relational databases, and NoSQL with connectors. Statements can be specified in any order, similar to spreadsheet formulas.
Who it's for
Python developers who need to perform complex queries, recursive logic, or rule-based reasoning without writing extensive imperative code. It's also useful for data integration, semantic web tasks, games, network analysis, and solving discrete constraint problems.
Highlights
- Adds Datalog, a declarative logic language, to Python's toolbox.
- More expressive than SQL with a cleaner syntax and recursion support.
- Works with multiple databases (memory, 11 relational DBs, NoSQL with connectors).
- Lets you define Python classes using logic clauses.
- Shortens programs compared to equivalent Python code.
- Cited in scientific papers and has a free video course and official documentation.
Related
- Project
- Project
- Project
- Project