fastrdf.config¶
fastrdf’s configuration as triples, in the model itself.
The configuration of a model, what it virtualizes, which indexes it has and how it caches query results, is kept in a named graph of its own, CONFIG_GRAPH, in the namespace CONFIG (https://datatreehouse.github.io/fastrdf/config#), together with its common questions (saved SPARQL queries, CommonQuestion) and its prefixes (PrefixConfig, SHACL prefix declarations). It travels with the model: written, serialized and served like any other graph, and applied with apply_config. See CONFIG_GRAPH.md for the vocabulary.
Secrets are never stored: a secret parameter names the environment variable that holds it, read when the configuration is applied.
>>> from fastrdf.config import VirtualizationConfig, VirtualizationResource, write_virtualization, apply_config
>>> write_virtualization(m, VirtualizationConfig(
... iri="urn:example:readings",
... database="snowflake",
... parameters={"account": "acme", "user": "fastrdf", "warehouse": "wh", "database": "meters", "schema": "public"},
... secrets={"password": "SNOWFLAKE_PASSWORD"},
... resources=[VirtualizationResource(name="readings", sql="SELECT id, ts AS timestamp, value FROM readings",
... template=READINGS_TEMPLATE)],
... ))
>>> apply_config(m) # connects and virtualizes
Attributes¶
Deprecated alias of FASTRDF: the time series virtualization vocabulary moved from the chrontext |
|
The namespace of fastrdf's configuration vocabulary. |
|
The named graph that holds the configuration of a model. |
|
The fastrdf vocabulary, which holds the time series virtualization vocabulary (fastrdf:hasTimeseries, |
|
The former namespace of the time series virtualization vocabulary. Deprecated: its IRIs are still |
|
Classes¶
A saved SPARQL query with a name and a description: a question people ask the model often. |
|
The indexes of the model. |
|
A prefix of the model: a short name for a namespace, used to write and show IRIs (ex:Pump for |
|
The query result cache of the model (Model.set_query_cache). Results are kept until a |
|
Any database SQLAlchemy connects to, by URL, queried with the given SQL dialect. |
|
A virtualized database: how to connect to it, and the resources it holds. |
|
A resource of a virtualized database: its rows (SQL) and the template they instantiate. |
Functions¶
|
Applies the configuration in the model's config graph: makes the configured prefixes known to |
|
Makes the configured prefixes (read from the config graph when not given) known to the |
|
Writes the static properties of the resources (VirtualizationResource.properties) on the |
|
Sets the model's query result cache to the configuration (read from the config graph when |
|
Connects to a configured database and virtualizes its resources in the model. |
|
Makes prefixes for the namespaces the data uses: the usual prefix of each well-known vocabulary |
|
The namespace of an IRI: up to its last '#' or '/' (for http and https IRIs), or its last ':' |
|
The IRI of the declaration of a prefix in the config graph. |
|
A short prefix name for a namespace: its last telling path segment (http://example.org/plant/ |
|
Checks a configuration against the database itself, without changing any model: connects and, |
|
The form of a SPARQL query (select, construct, ask or describe), after its prologue and |
|
A new IRI for a common question, from its name and a random part. |
|
The indexes in the configuration (none when it does not say). |
|
The prefixes in the configuration (the SHACL prefix declarations in the config graph), by name. |
|
The query result cache in the configuration, None when it does not say. |
|
The common questions in the configuration, in their order (sh:order, then name). With a domain |
|
The virtualized databases in the configuration. |
|
Removes a prefix from the configuration. |
Removes the query result cache from the configuration (the model's setting stays). |
|
|
Removes a common question from the configuration. |
|
Removes a virtualized database from the configuration (a virtualization already applied stays). |
|
fastrdf's well-known prefixes, from namespace to name (fastrdf.well_known_prefixes(), the |
|
Sets the indexes of the model in the configuration. |
|
Adds a prefix to the configuration, or replaces the one with its name. |
|
Adds prefixes to the configuration, replacing those with the same names. A namespace has one |
|
Sets the query result cache of the model in the configuration. |
|
Adds a common question to the configuration, or replaces the one with its IRI. |
|
Adds a virtualized database to the configuration, or replaces the one with its IRI. |
Module Contents¶
- class fastrdf.config.CommonQuestion¶
A saved SPARQL query with a name and a description: a question people ask the model often. In the config graph a mcfg:CommonQuestion, which is a SHACL-AF SPARQL executable (sh:select, sh:construct or sh:ask holds the query).
- applies_to: str | None = None¶
mcfg:appliesTo: the vocabulary (namespace IRI) of the data it is about, e.g. one of QUESTION_DOMAINS; None for a question about any model.
- bundled: bool = False¶
mcfg:bundled: one of the questions fastrdf ships (fastrdf.bundled_questions).
- class fastrdf.config.IndexingConfig¶
The indexes of the model.
- options() fastrdf.IndexingOptions¶
The IndexingOptions that create these indexes.
- class fastrdf.config.PrefixConfig¶
A prefix of the model: a short name for a namespace, used to write and show IRIs (ex:Pump for http://example.org/Pump). In the config graph a SHACL prefix declaration (sh:prefix, sh:namespace), declared (sh:declare) by the owl:Ontology PREFIXES.
- class fastrdf.config.QueryCacheConfig¶
The query result cache of the model (Model.set_query_cache). Results are kept until a write changes the triples they read, per named graph and predicate.
- options() fastrdf.QueryCacheOptions¶
The QueryCacheOptions for Model.set_query_cache.
- class fastrdf.config.SQLAlchemyDatabase(url: str, sql_dialect: str, password: str | None = None)¶
Any database SQLAlchemy connects to, by URL, queried with the given SQL dialect.
- engine¶
- sql_dialect¶
- class fastrdf.config.VirtualizationConfig¶
A virtualized database: how to connect to it, and the resources it holds.
- resources: List[VirtualizationResource] = []¶
- class fastrdf.config.VirtualizationResource¶
A resource of a virtualized database: its rows (SQL) and the template they instantiate.
- options: Dict[str, str]¶
Further settings of the resource, e.g. for CDF id_type (external_id, id or instance_id).
- properties: Dict[str, str]¶
Static properties of the objects it virtualizes: predicate IRI to object IRI, e.g. the unit of a measurement (cim:Measurement.unitSymbol to cim:UnitSymbol.W). Applying the virtualization writes them as ordinary triples on each object with fastrdf:hasResource the resource name (in the default graph), replacing the values those objects had for the predicate. Constant triples in a virtualized template are not supported by chrontext, so this is where such facts go.
- fastrdf.config.apply_config(m: fastrdf.Model, environ: Mapping[str, str] | None = None) List[str]¶
Applies the configuration in the model’s config graph: makes the configured prefixes known to the model, creates the configured indexes, sets the query result cache and virtualizes the enabled databases.
- Parameters:
m – The model.
environ – Where the secrets are read from, by default the environment variables.
- Returns:
The IRIs of the virtualizations applied.
- fastrdf.config.apply_prefixes(m: fastrdf.Model, prefixes: List[PrefixConfig] | None = None)¶
Makes the configured prefixes (read from the config graph when not given) known to the model, for parsing SPARQL, Datalog and OTTR (Model.add_prefixes).
- fastrdf.config.apply_properties(m: fastrdf.Model, config: VirtualizationConfig)¶
Writes the static properties of the resources (VirtualizationResource.properties) on the objects they virtualize, those with fastrdf:hasResource the resource name, in the default graph. A property replaces the values the objects had for its predicate, so changing a unit and applying again leaves only the new one.
- fastrdf.config.apply_query_cache(m: fastrdf.Model, config: QueryCacheConfig | None = None)¶
Sets the model’s query result cache to the configuration (read from the config graph when not given). Does nothing when the configuration has none.
- fastrdf.config.apply_virtualization(m: fastrdf.Model, config: VirtualizationConfig, environ: Mapping[str, str] | None = None)¶
Connects to a configured database and virtualizes its resources in the model.
- fastrdf.config.generate_prefixes(m: fastrdf.Model, graph: None | str | List[str | None] = None, max_generated: int = GENERATED_PREFIXES, write: bool = True) List[PrefixConfig]¶
Makes prefixes for the namespaces the data uses: the usual prefix of each well-known vocabulary in it (fastrdf.well_known_prefixes(): rdf, rdfs, xsd, owl, sh, skos, dcterms, prov, geo, cim, opc, …), and a short name (prefix_name_for) for the max_generated namespaces it uses most besides these. Namespaces that have a prefix already (in the config graph, or declared with sh:prefix in any graph) keep it, and names in use are not given again.
- Parameters:
m – The model.
graph – The named graph whose data is looked at, by default the default graph; or a list of graphs (None in it for the default graph), whose uses of each namespace are added up.
max_generated – How many namespaces that are not well known get a prefix at most.
write – Writes the new prefixes to the config graph (as generated, mcfg:generated true).
- Returns:
The new prefixes.
- fastrdf.config.namespace_of(iri: str) str | None¶
The namespace of an IRI: up to its last ‘#’ or ‘/’ (for http and https IRIs), or its last ‘:’ for other schemes (urn:example:pump:1 has urn:example:pump:). None when there is no local name.
- fastrdf.config.prefix_iri(name: str) str¶
The IRI of the declaration of a prefix in the config graph.
- fastrdf.config.prefix_name_for(namespace: str) str¶
A short prefix name for a namespace: its last telling path segment (http://example.org/plant/ is plant), else the name of its host (http://data.example.org/ is example).
- fastrdf.config.probe(config: VirtualizationConfig, sql: str | None = None, environ: Mapping[str, str] | None = None) dict¶
Checks a configuration against the database itself, without changing any model: connects and, for an SQL database, runs the SQL (LIMIT 5, in KQL: take 5) and returns its columns and a sample; for Cognite Data Fusion inspects the token and lists some time series; for InfluxDB without SQL, and InfluxDB 2, lists the measurements; for OPC UA connects to the endpoint; for IP.21 searches for some tags.
- Returns:
A dict with “message”, and “columns” (name and polars type) and “sample” (rows) when there are rows to show.
- fastrdf.config.query_form(query: str) str¶
The form of a SPARQL query (select, construct, ask or describe), after its prologue and comments. Raises ValueError for an update or anything else that is not a query.
- fastrdf.config.question_iri(name: str) str¶
A new IRI for a common question, from its name and a random part.
- fastrdf.config.read_indexing(m: fastrdf.Model) IndexingConfig¶
The indexes in the configuration (none when it does not say).
- fastrdf.config.read_prefixes(m: fastrdf.Model) List[PrefixConfig]¶
The prefixes in the configuration (the SHACL prefix declarations in the config graph), by name.
- fastrdf.config.read_query_cache(m: fastrdf.Model) QueryCacheConfig | None¶
The query result cache in the configuration, None when it does not say.
- fastrdf.config.read_questions(m: fastrdf.Model, domain: str | None = None) List[CommonQuestion]¶
The common questions in the configuration, in their order (sh:order, then name). With a domain (one of QUESTION_DOMAINS, or a vocabulary IRI), only those that apply to it and those that apply to any model.
- fastrdf.config.read_virtualizations(m: fastrdf.Model) List[VirtualizationConfig]¶
The virtualized databases in the configuration.
- fastrdf.config.remove_prefix(m: fastrdf.Model, name: str)¶
Removes a prefix from the configuration.
- fastrdf.config.remove_query_cache(m: fastrdf.Model)¶
Removes the query result cache from the configuration (the model’s setting stays).
- fastrdf.config.remove_question(m: fastrdf.Model, iri: str)¶
Removes a common question from the configuration.
- fastrdf.config.remove_virtualization(m: fastrdf.Model, iri: str)¶
Removes a virtualized database from the configuration (a virtualization already applied stays).
- fastrdf.config.well_known_prefixes() Dict[str, str]¶
fastrdf’s well-known prefixes, from namespace to name (fastrdf.well_known_prefixes(), the one table of default prefixes, kept in Rust): the names generate_prefixes gives the vocabularies it finds. cim is CIM100; CIM16 is cim16.
- fastrdf.config.write_indexing(m: fastrdf.Model, config: IndexingConfig)¶
Sets the indexes of the model in the configuration.
- fastrdf.config.write_prefix(m: fastrdf.Model, prefix: PrefixConfig)¶
Adds a prefix to the configuration, or replaces the one with its name.
- fastrdf.config.write_prefixes(m: fastrdf.Model, prefixes: List[PrefixConfig])¶
Adds prefixes to the configuration, replacing those with the same names. A namespace has one prefix: writing a prefix for a namespace that has another one raises ValueError.
- fastrdf.config.write_query_cache(m: fastrdf.Model, config: QueryCacheConfig)¶
Sets the query result cache of the model in the configuration.
- fastrdf.config.write_question(m: fastrdf.Model, question: CommonQuestion)¶
Adds a common question to the configuration, or replaces the one with its IRI.
- fastrdf.config.write_virtualization(m: fastrdf.Model, config: VirtualizationConfig)¶
Adds a virtualized database to the configuration, or replaces the one with its IRI.
- fastrdf.config.CHRONTEXT = 'https://datatreehouse.github.io/fastrdf/vocab#'¶
Deprecated alias of FASTRDF: the time series virtualization vocabulary moved from the chrontext namespace (LEGACY_CHRONTEXT) to the fastrdf vocabulary.
- fastrdf.config.CONFIG = 'https://datatreehouse.github.io/fastrdf/config#'¶
The namespace of fastrdf’s configuration vocabulary.
- fastrdf.config.CONFIG_GRAPH = 'https://datatreehouse.github.io/fastrdf/config#ConfigGraph'¶
The named graph that holds the configuration of a model.
- fastrdf.config.DCTERMS = 'http://purl.org/dc/terms/'¶
- fastrdf.config.FASTRDF = 'https://datatreehouse.github.io/fastrdf/vocab#'¶
The fastrdf vocabulary, which holds the time series virtualization vocabulary (fastrdf:hasTimeseries, fastrdf:hasDataPoint, fastrdf:hasTimestamp, fastrdf:hasValue, fastrdf:hasResource, fastrdf:hasExternalId, fastrdf:FloorDateTimeToSecondsInterval, fastrdf:dateBin, …).
- fastrdf.config.GENERAL_SQL = 'sql'¶
- fastrdf.config.GENERATED_PREFIXES = 8¶
- fastrdf.config.KQL_DATABASES = ('kusto',)¶
- fastrdf.config.LEGACY_CHRONTEXT = 'https://github.com/DataTreehouse/chrontext#'¶
The former namespace of the time series virtualization vocabulary. Deprecated: its IRIs are still accepted in queries, in the predicates of data and in virtualization templates, and are read as the IRI with the same local name in FASTRDF.
- fastrdf.config.OWL = 'http://www.w3.org/2002/07/owl#'¶
- fastrdf.config.PREFIXES = 'https://datatreehouse.github.io/fastrdf/config#prefixes'¶
- fastrdf.config.QUESTION_IRI_PREFIX = 'urn:fastrdf:config:question:'¶
- fastrdf.config.RDFS_LABEL = 'http://www.w3.org/2000/01/rdf-schema#label'¶
- fastrdf.config.RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'¶
- fastrdf.config.SELF_DESCRIBING = ('osipi', 'pi_points', 'ip21', 'insights_hub')¶
- fastrdf.config.SHACL = 'http://www.w3.org/ns/shacl#'¶
- fastrdf.config.SQL_DATABASES = ('sql', 'duckdb', 'snowflake', 'bigquery', 'databricks', 'timescale', 'fabric_lakehouse',...¶
- fastrdf.config.SQL_DIALECTS = ('duckdb', 'postgres', 'snowflake', 'bigquery', 'databricks')¶
- fastrdf.config.TSQL_DATABASES = ('fabric_warehouse',)¶
- fastrdf.config.XSD = 'http://www.w3.org/2001/XMLSchema#'¶