Linked-Data Python
Python, with the Semantic Web in its syntax. IRIs, prefixed names, RDF literals, SPARQL variables and whole graphs written in Turtle's notation are expressions of the language — interpolated with arbitrary Python, transpiled to plain Python, running on rdflib.
@prefix sosa: <http://www.w3.org/ns/sosa/> .
@base <http://example.org/building/> .
def observation(sensor, value):
return g{ f<sensor/{sensor}> a sosa:Sensor ;
sosa:madeObservation [ sosa:hasSimpleResult {value} ] }
The language also reads and queries, writes into a current graph, and turns rows into triples:
@prefix ex: <http://example.org/> .
@graph as kg
for @bindings in csv.DictReader(f): # any iterable of mappings
+{ e<http://example.org/{?id}> ex:value ?v }
for s, v in m{ ?s ex:value ?v }: # a graph pattern, no engine
...
rows = s{ SELECT ?s WHERE { ?s ex:value ?v } } # all of SPARQL, checked early
adult = e{ ?age >= 18 && BOUND(?name) } # deferred, over bindings
.ldpy files are transpiled to plain Python by an island parser: the
Python is copied verbatim — every valid Python file is a valid ldpy file,
returned byte-identical — and only the RDF islands are parsed and rewritten.
The transpiler is ~1 500 lines with no parsing dependency and sustains
56 000–110 000 source lines/s depending on island density.
Quick start
git clone https://github.com/linked-data-python/ldpy.git
cd linked-data-python && pip install -e . # or: pip install -e .[lsp,debug]
ldpy program.ldpy # run a file
ldpy # interactive console
ldpy-lsp # language server (LSP, stdio)
ldpy-debug program.ldpy # debug via the shadow .py + debugpy
From Python: import ldpy; ldpy.install() then import yourmodule finds
yourmodule.ldpy on sys.path.
Documentation
Read it at docs/ — start with the
home page for an overview, then:
- Tutorials — first steps, then build a knowledge graph from tabular data.
- How-to guides — run & import, build graphs from tables, read and query, migrate from rdflib, VS Code, debugging, language server, highlighting.
- Reference — the language, one page per island family; SPARQL expressions; CLI; Python API; language map formats.
- Explanation — why, what real RDF code does (the corpus study that drove the language's second wave), designing the syntax, island parsing, emission & semantics, tooling, how this is tested.
Every ldpy and python block in the documentation is executed by the test
suite, and its assertions are the test.
Tooling
- VS Code extension (
vscode-ldpy): highlighting (TextMate + LSP semantic tokens), diagnostics as you type, completion/hover/definition, run and debug. - Language server: dependency-free, LSP over stdio; delegates Python
intelligence to an unmodified
pylspthrough the language map. - Debugging:
.ldpycode compiles in.ldpycoordinates, sopdbanddebugpywork directly;ldpy.buildalso materialises real.pyshadow files with JSON and Source Map v3 maps. - Highlighting anywhere else: the package registers a Pygments lexer built
on the language map — MkDocs, Sphinx and
pygmentizecolour.ldpywith no further setup. - Benchmark harness (
bench/): seeded random program generator and reproducible throughput campaigns.
Project
- Tests:
python -m pytest tests/ -q— byte-identity over the CPython standard library, golden transpilation, RDF isomorphism against rdflib as an oracle, LSP end to end, executable documentation. - Licence: MIT. Author: Maxime Lefrançois (Mines Saint-Étienne).
- The 2023 ANTLR-based release (v1, PyPI 0.0.4) is preliminary work, superseded
by this island-parsing rewrite (the
mainbranch of this repository; the 2023 code remains on the legacy gitlab.com/coswot/ldpy).
Design records
Every non-trivial choice in this repository is written down, one file per
decision, in the pilotage repository. Comments and docs
cite them by identifier — ldpy/024, vscode/103 — which resolves to
design/.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file linked_data_python-0.2.0.tar.gz.
File metadata
- Download URL: linked_data_python-0.2.0.tar.gz
- Upload date:
- Size: 131.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a12e7777b3dbd11dfa09bc0cbe91400bcfd83296fb69711115982c339e7649
|
|
| MD5 |
a666d2f6ceeb1d256a90e8d45279cb40
|
|
| BLAKE2b-256 |
89e77862c87ae75bb43bad7e501dacf1f2725aefded0aac98eca60cb8bfb514c
|
File details
Details for the file linked_data_python-0.2.0-py3-none-any.whl.
File metadata
- Download URL: linked_data_python-0.2.0-py3-none-any.whl
- Upload date:
- Size: 82.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624ac7caf2d2789971b6dd2e21325878fc15db197f61c2f7d872e3f9afe7c9c6
|
|
| MD5 |
cb2cc755a5fc7c371b65bd8d42b8746c
|
|
| BLAKE2b-256 |
46dd016b8033b7b4cd7b0f44cd8166711228acef968a2e5667d8f80b1652ea42
|