Skip to content

(feat) Add Relation and Tuple operations to Python SWIG bindings - #2571

Open
qequ wants to merge 2 commits into
souffle-lang:masterfrom
qequ:feature/expand-python-interface
Open

(feat) Add Relation and Tuple operations to Python SWIG bindings#2571
qequ wants to merge 2 commits into
souffle-lang:masterfrom
qequ:feature/expand-python-interface

Conversation

@qequ

@qequ qequ commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

This PR extends the Python SWIG interface to support programmatic access to Relations and Tuples, enabling direct manipulation of Souffle data structures from Python without file I/O.

New Features

SWIGRelation - Access relations by name with metadata queries (arity, size, attribute types/names)
SWIGTuple - Create and read tuples with typed accessors (putString, putInt, putUInt, putFloat and corresponding getters)
SWIGRelationIterator - Iterate over relation tuples with Python's native for loop syntax
Tuple operations - insert(), contains(), purge() for programmatic data manipulation

Example Usage

import SwigInterface

p = SwigInterface.newInstance('myprogram')

# Insert tuples programmatically
edge = p.getRelation('edge')
t = edge.createTuple()
t.putString("A")
t.putString("B")
edge.insert(t)

p.run()

# Iterate over results
for t in p.getRelation('path'):
    print(t.getString(), t.getString())

qequ added 2 commits January 8, 2026 20:06
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant