Skip to main content

A templating engine for SPARQL queries with typed, injection-safe placeholders and loops

Project description

Triplate (Python)

A templating engine for RDF query & data languages (SPARQL, Turtle, …) with a typed --- frontmatter header, injection-safe values, loops and conditionals. Python reference implementation of the Triplate language.

from triplate import compile

template = """\
---
params {
  classes: iri[] min 1
  limit:   int optional
}
---
SELECT ?s WHERE {
{% for c in classes join "UNION" %}
  { ?s a ${c} }
{% endfor %}
}
{% if limit %}LIMIT ${limit}{% endif %}
"""

tmpl = compile(template)
sparql = tmpl.render(classes=["http://example.org/Person"], limit=10)

Every input is declared in the mandatory --- frontmatter header with its RDF type; the context is validated and each value escaped accordingly, so rendered output is injection-safe and an unprocessed template fails fast.

See triplate.dev for the full guide and specification.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

triplate-0.4.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

triplate-0.4.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file triplate-0.4.0.tar.gz.

File metadata

  • Download URL: triplate-0.4.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplate-0.4.0.tar.gz
Algorithm Hash digest
SHA256 43ddd875a649541d0f96e6ecc567d64b6b8627abd1d10b2e8580f70f0ea6e636
MD5 ff21a2260482e86c6b4b58f1511b1956
BLAKE2b-256 b1145638bb9009e9d12bdc14abe595beb09e80208da4470262ad32b9fd2727b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplate-0.4.0.tar.gz:

Publisher: release-please.yml on triplate/triplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file triplate-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: triplate-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triplate-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6a2843f24665c4d09d04ceef9b5ca5101948b573a1cb46204223338f19ae86f
MD5 e3bad6ecf378a96fd4239012116f7c04
BLAKE2b-256 64ee5a660a95939703e9b8127524639a62ce0125928c7c3dad74d8d32e95418c

See more details on using hashes here.

Provenance

The following attestation bundles were made for triplate-0.4.0-py3-none-any.whl:

Publisher: release-please.yml on triplate/triplate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page