Skip to main content

ouisparql - Simple SPARQL in Python

SPARQL is code. Write it, version control it, comment it, and run it using files. Writing your SPARQL code in Python programs as strings doesn’t allow you to easily reuse them in SPARQL GUIs or CLI tools. With ouisparql you can organize your SPARQL statements in .sparql files, load them into your python application as methods to call without losing the ability to use them as you would any other SPARQL file.

This module is an implementation of Kris Jenkins’ yesql Clojure library to the Python ecosystem, adapted from aiosql for SPARQL.

Badges

Usage

Install from pypi, for instance by running pip install ouisparql.

Install with pip from gitlab:

pip install  git+https://gitlab.com/sortion/ouisparql.git@main

Then write parametric SPARQL queries in a file and execute it from Python methods, e.g., this predicates.sparql file:

# name: get_predicates()
# Get the first two predicates in the database
SELECT DISTINCT ?predicate
WHERE {
      ?subject ?predicate ?object .
}

# name: get_subject_by_predicate(predicate)
# Get the first two subjects from a given predicate using a named parameter
SELECT DISTINCT ?subject
WHERE {
      ?subject :predicate ?object .
}

This example has an imaginary SPARQL endpoint with RDF triplets. It displays all predicates in the first example, and all subjects associated with a given predicate.

OuiSPARQL main feature is to be able to load queries from a SPARQL file and call them by name in python code. Query parameter declarations (e.g., (predicate)) are optional, and enforced when provided.

You can use ouisparql to load the queries in this file for use in your Python application:

import ouisparql
from SPARQLWrapper import SPARLQWrapper
sparql = SPARQLWrapper("https://query.wikidata.org/sparql", agent="OuiSPARQL documentation")
queries = ouisparql.from_path("queries.rq", "sparql_wrapper")
queries.get_all_predicate()
queries.get_subjects_by_predicate(predicate)

Why you might want to use this

  • You think SPARQL is pretty good, and writing SPARQL is an important part of your applications.

  • You don’t want to write your SPARQL in strings intermixed with your python code.

  • You want to be able to reuse your SPARQL in other contexts, e.g., loading it into a SPARQL endpoint or other tools.

Why you might NOT want to use this

  • You aren’t comfortable writing SPARQL code.

  • Dynamically loaded objects built at runtime really bother you.

Metadata

Release files for ouisparql 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ouisparql 0.2.0
File Size Uploaded Provenance
ouisparql-0.2.0.tar.gz 203.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ouisparql 0.2.0
File Interpreter ABI Platform
ouisparql-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 224.8 kB

Release files / ouisparql-0.2.0.tar.gz

Download URL ouisparql-0.2.0.tar.gz
Size 203.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0dcc9fd35f5a3b9b389cc30d4f2c03086b7a7d766dd29a1806a30a423380fd8b
BLAKE2b-256 checksum
How to use checksums
22483e5903022bfe9c2f8dadcfd163db3bf80b4003dc345dc381dca5d374c54e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / ouisparql-0.2.0-py3-none-any.whl

Download URL ouisparql-0.2.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2989d9d511111a2f72b69d82d7f1f0611593696c57eb31dbbe156e4eec60409
BLAKE2b-256 checksum
How to use checksums
375548894537aefa8efd3fb955bdb381f7ae0bd3f2c5006b3f94f49ea21a4d73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.9.25

Security for ouisparql 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page