Embed the data source specifications in your JINJA templates directly, and enjoy the dynamic data contexts.
Project description
eds4jinja2
An easy way to reports generation with Jinja2 templates.
With Embedded Datasource Specifications inside Jinja2 templates, you can fetch the data you need on the spot.
Specify the data sources in your JINJA templates directly.
{% set content, error = from_file(path).fetch_tree() %} \n
content: {{ content }}\n
error: {{ error }}\n
{% set content, error =
from_endpoint(endpoint).with_query(query_string).fetch_tabular() %}
content: {{ content }} \n
error: {{ error }} \n
Installation
pip install eds4jinja2
For the optional fast in-memory SPARQL engine (oxigraph), install the extra:
pip install eds4jinja2[oxigraph]
Usage
In-memory graph data sources
Besides a remote SPARQL endpoint (from_endpoint) and tabular/RDF files, reports can be
rendered against an in-process RDF graph — no SPARQL server required. Two builders are
available in templates:
from_graph(graph)— query an in-memory graph/store you already hold (anrdflib.Graph, apyoxigraphstore, or anyquery(sparql)callable). Alias:from_memory.from_rdf(sources, engine="rdflib")— load one or more RDF files/URLs into an in-memory graph once (engine:"rdflib"default, or"oxigraph") and query it. Both tabular (fetch_tabular) and tree (fetch_tree) results are supported.
To render an existing report against an in-memory graph with the templates unchanged,
inject a builder that overrides from_endpoint (which the templates already call):
import rdflib
from eds4jinja2 import InMemorySPARQLDataSource
from eds4jinja2.services.report_builder import ReportBuilder
graph = rdflib.Graph().parse("dataset.ttl") # the consumer owns loading/manipulation
ReportBuilder(
"report/",
external_data_source_builders={"from_endpoint": lambda _endpoint: InMemorySPARQLDataSource(graph)},
).make_document()
Parallel report execution
For large reports whose runtime is dominated by SPARQL query latency, set parallelism in the
report config.json to pre-warm all data fetches concurrently before rendering:
{ "template": "report.html", "conf": {}, "parallelism": 16 }
Execution is threads-only and all-or-nothing (any fetch failure aborts the report, no
partial output); results are staged in a temp folder that is cleaned up afterwards. With
parallelism unset or 1 the behaviour is exactly the previous sequential render. Threaded
speed-up is real for remote endpoints and oxigraph in-memory graphs (both release the GIL);
rdflib in-memory queries are GIL-bound (correct, limited speed-up).
Contributing
You are more than welcome to help expand and mature this project. We adhere to Apache code of conduct, please follow it in all your interactions on the project.
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the maintainers of this repository before making a change.
Licence
This project is licensed under Apache License 2.0. Powered by Meaningfy.
Project details
Release history Release notifications | RSS feed
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 eds4jinja2-1.0.0.tar.gz.
File metadata
- Download URL: eds4jinja2-1.0.0.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d9a48ed61f4d2c6a3f9829458d097ac12b4ca65434be496121a5ad22141643
|
|
| MD5 |
1c4e6607dcd5bda9298ef23709178cc1
|
|
| BLAKE2b-256 |
fdebc2a9c756485c36b214aa43f5f1ad1fcaba51ab8e057d3f34acd775f12843
|
Provenance
The following attestation bundles were made for eds4jinja2-1.0.0.tar.gz:
Publisher:
publish.yml on meaningfy-ws/eds4jinja2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eds4jinja2-1.0.0.tar.gz -
Subject digest:
a6d9a48ed61f4d2c6a3f9829458d097ac12b4ca65434be496121a5ad22141643 - Sigstore transparency entry: 1870595865
- Sigstore integration time:
-
Permalink:
meaningfy-ws/eds4jinja2@7f6bcb0844fb2cf21ddec964c2609514389dea2c -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/meaningfy-ws
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7f6bcb0844fb2cf21ddec964c2609514389dea2c -
Trigger Event:
release
-
Statement type:
File details
Details for the file eds4jinja2-1.0.0-py3-none-any.whl.
File metadata
- Download URL: eds4jinja2-1.0.0-py3-none-any.whl
- Upload date:
- Size: 39.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0886c380a6bc59df5f358369e113855ed2b19b1cfdd78f382e9e4df01d8ae41f
|
|
| MD5 |
c4cac4cb87d3ef639b21951b619e0185
|
|
| BLAKE2b-256 |
313b04485c86497af1457bc110e88c64ddd4d912a00c70fb7130befa879835fb
|
Provenance
The following attestation bundles were made for eds4jinja2-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on meaningfy-ws/eds4jinja2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eds4jinja2-1.0.0-py3-none-any.whl -
Subject digest:
0886c380a6bc59df5f358369e113855ed2b19b1cfdd78f382e9e4df01d8ae41f - Sigstore transparency entry: 1870595962
- Sigstore integration time:
-
Permalink:
meaningfy-ws/eds4jinja2@7f6bcb0844fb2cf21ddec964c2609514389dea2c -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/meaningfy-ws
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7f6bcb0844fb2cf21ddec964c2609514389dea2c -
Trigger Event:
release
-
Statement type: