Skip to main content

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:

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 pylsp through the language map.
  • Debugging: .ldpy code compiles in .ldpy coordinates, so pdb and debugpy work directly; ldpy.build also materialises real .py shadow 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 pygmentize colour .ldpy with 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 main branch 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

linked_data_python-0.6.1.tar.gz (155.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linked_data_python-0.6.1-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

Details for the file linked_data_python-0.6.1.tar.gz.

File metadata

  • Download URL: linked_data_python-0.6.1.tar.gz
  • Upload date:
  • Size: 155.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for linked_data_python-0.6.1.tar.gz
Algorithm Hash digest
SHA256 bf97aeae9431568d2673422c888f676545b240b2cf81ae49245c0a85834f608b
MD5 ad35db6af9764daa7acb1dba8f62d0a1
BLAKE2b-256 fb1880494af35207c55eb773cc95e448fca628a717d79b793a55ac799eabcb57

See more details on using hashes here.

File details

Details for the file linked_data_python-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for linked_data_python-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e412a48aaa1b29227e7260c8de5f85127f6502a76c2852264809b5350c1a4d2
MD5 a74413ade39da86e51b1dbb2e4ffff01
BLAKE2b-256 f6ca861a731abd58b85bea24f62ad9b6d16013813b8f21a65cef1961e74c3b0e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

This release

0.6.1 This release

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.2.1

2 files

0.2.0

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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