Connectors SQLite

SQLite

File

The SQLite connector is a file connector that queries a local SQLite database and maps rows to claims. It uses Python’s built-in sqlite3 module — zero external dependencies required.

How it works

Key features

FeatureDescription
Zero dependenciesUses Python stdlib sqlite3 — nothing to install.
Full SQLAny valid SQLite query works: joins, subqueries, CTEs, aggregations.
Column mappingMap any result column to subject, predicate, object, and optional type fields.
Read-onlyOpens the database in read-only mode. No writes to your data.

1 No external dependencies required

The SQLite connector uses Python’s built-in sqlite3 module. There is nothing to install.

2 Have a SQLite database file

You need a .db or .sqlite file with the table or view you want to query. Know the schema so you can write a query and define your column mapping.

3 Connect

conn = db.connect("sqlite",
    path="data/interactions.db",
    query="SELECT gene, relation, target FROM interactions",
    mapping={"subject": "gene", "predicate": "relation", "object": "target"},
)
result = conn.run(db)
Parameter Required Default Description
path Yes Path to the SQLite database file
query Yes SQL query to execute
mapping Yes Column-to-claim field mapping (dict)
source_type No database_import Provenance source type
save No False N/A (no credentials to store)

Mapping fields

The mapping dict maps claim fields to column names in your query result:

Claim fieldRequiredDescription
subjectYesColumn containing the subject entity
predicateYesColumn containing the predicate (relationship)
objectYesColumn containing the object entity
subject_typeNoColumn or literal string for subject entity type
object_typeNoColumn or literal string for object entity type

Basic usage

conn = db.connect("sqlite",
    path="data/interactions.db",
    query="SELECT gene, relation, target FROM interactions",
    mapping={"subject": "gene", "predicate": "relation", "object": "target"},
)
result = conn.run(db)

With a JOIN query

conn = db.connect("sqlite",
    path="data/knowledge.db",
    query="""
        SELECT e1.name AS src, r.type AS rel, e2.name AS dst
        FROM relationships r
        JOIN entities e1 ON r.source_id = e1.id
        JOIN entities e2 ON r.target_id = e2.id
    """,
    mapping={"subject": "src", "predicate": "rel", "object": "dst"},
)
result = conn.run(db)

With type mapping

conn = db.connect("sqlite",
    path="data/bio.db",
    query="SELECT drug, action, gene FROM drug_targets",
    mapping={
        "subject": "drug",
        "predicate": "action",
        "object": "gene",
        "subject_type": "compound",
        "object_type": "gene",
    },
)
result = conn.run(db)

Related Connectors