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 https://linked-data-python.readthedocs.io/ — 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/.
Metadata
Release files for linked-data-python 0.6.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| linked_data_python-0.6.5.tar.gz | 164.9 kB | Without provenance | Details for linked_data_python-0.6.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| linked_data_python-0.6.5-py3-none-any.whl | Python 3 | none | any | Details for linked_data_python-0.6.5-py3-none-any.whl |
Total release size: 266.3 kB
Release files / linked_data_python-0.6.5.tar.gz
| Download URL | linked_data_python-0.6.5.tar.gz |
|---|---|
| Size | 164.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4ef4748de55a47e554c92768fab2336285a91beb4bddb22f3cec71208155ed8
|
|
BLAKE2b-256 checksum How to use checksums |
a1c1c1e845221cce8b2301af0fc9270d9d671c8f759481d5a57a2e20f5e63694
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / linked_data_python-0.6.5-py3-none-any.whl
| Download URL | linked_data_python-0.6.5-py3-none-any.whl |
|---|---|
| Size | 101.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76b9066a3082e84ed3c3fe290184534e8c68e0e3aadfac41a84b59771ddf1bd9
|
|
BLAKE2b-256 checksum How to use checksums |
a46ac01616033a3cf7926397a7360e2081974b9d6530f24d7f0fea690e556645
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for linked-data-python 0.6.5
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.