### Example Accessing pyoxigraph.Literal Value Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Provides a Python example demonstrating how to access the `value` property of a `pyoxigraph.Literal` instance, returning its lexical form. ```Python Literal("example").value 'example' ``` -------------------------------- ### Example Accessing pyoxigraph.Literal Language Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Provides Python examples demonstrating how to access the `language` property of `pyoxigraph.Literal` instances. It shows the language tag for a language-tagged literal and `None` for a literal without a language tag. ```Python Literal('example', language='en').language 'en' Literal('example').language ``` -------------------------------- ### Python: pyoxigraph.QueryTriples Class Overview and CONSTRUCT Query Example Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Documents the `pyoxigraph.QueryTriples` class, an iterator for `Triple` objects returned by SPARQL `CONSTRUCT` or `DESCRIBE` queries. Includes an example demonstrating how to add a quad to a `Store` and execute a `CONSTRUCT` query to retrieve triples. ```APIDOC pyoxigraph.QueryTriples: Description: An iterator of Triple returned by a SPARQL CONSTRUCT or DESCRIBE query ``` ```Python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) list(store.query('CONSTRUCT WHERE { ?s ?p ?o }')) ``` -------------------------------- ### Bulk load into pyoxigraph 0.3 Store after migration Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/migration After dumping the content from pyoxigraph 0.2, this snippet shows how to bulk load the data into the new `Store` class in pyoxigraph version 0.3. This completes the migration of the on-disk storage system from `SledStore` to `Store`. ```Python from pyoxigraph import Store store = Store('MY_NEW_STORAGE_PATH') with open('temp_file.nq', 'rb') as fp: store.bulk_load(fp, "application/n-quads") ``` -------------------------------- ### Execute SPARQL CONSTRUCT Query with pyoxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Illustrates the use of the `pyoxigraph.Store.query` method for executing a SPARQL `CONSTRUCT` query. The example sets up a store, adds a triple, and then constructs new triples based on the query pattern. ```Python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) list(store.query('CONSTRUCT WHERE { ?s ?p ?o }')) ``` -------------------------------- ### Python Example: QueryResultsFormat.from_extension() Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Demonstrates how to use `QueryResultsFormat.from_extension()` to get a format object from a file extension like 'json'. ```python >>> QueryResultsFormat.from_extension("json") ``` -------------------------------- ### Dump PyOxigraph Store to Turtle Format with Graph and Prefixes Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Illustrates dumping a PyOxigraph `Store`'s content to a `BytesIO` object using the Turtle format. This example includes adding a quad to a named graph and specifies a base IRI and prefixes for the serialization, demonstrating more advanced usage of the `dump` method. ```python import io store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) output = io.BytesIO() store.dump(output, RdfFormat.TURTLE, from_graph=NamedNode("http://example.com/g"), prefixes={"ex": "http://example.com/"}, base_iri="http://example.com") output.getvalue() # Expected output: b'@base .\n@prefix ex: .\n<> ex:p "1" .\n' ``` -------------------------------- ### Migrate pyoxigraph On-Disk Store Content from 0.2 to 0.3 Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/migration.rst To migrate on-disk store content from pyoxigraph 0.2 (using SledStore) to pyoxigraph 0.3 (using the new Store class), first dump the existing store's content to a temporary file using version 0.2, then upgrade to version 0.3 and bulk load the data into the new Store. This ensures data continuity despite the underlying storage system change. ```python from pyoxigraph import SledStore store = SledStore('MY_STORAGE_PATH') with open('temp_file.nq', 'wb') as fp: store.dump(fp, "application/n-quads") ``` ```python from pyoxigraph import Store store = Store('MY_NEW_STORAGE_PATH') with open('temp_file.nq', 'rb') as fp: store.bulk_load(fp, "application/n-quads") ``` -------------------------------- ### Insert and Query Triple in Pyoxigraph with SPARQL Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/index.rst This Python example demonstrates how to initialize a Pyoxigraph store, add a triple using NamedNode and Literal objects, and then execute a SPARQL SELECT query to retrieve and print the value of a specific binding from the store. ```Python from pyoxigraph import * store = Store() ex = NamedNode('http://example/') schema_name = NamedNode('http://schema.org/name') store.add(Quad(ex, schema_name, Literal('example'))) for binding in store.query('SELECT ?name WHERE { ?name }'): print(binding['name'].value) ``` -------------------------------- ### Example Accessing pyoxigraph.Literal Datatype Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Provides Python examples demonstrating how to access the `datatype` property of `pyoxigraph.Literal` instances. It shows the resulting `NamedNode` for literals with explicit integer datatypes, default string datatypes, and language-tagged strings. ```Python Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer')).datatype Literal('example').datatype Literal('example', language='en').datatype ``` -------------------------------- ### Python Example: QueryResultsFormat.name Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Illustrates how to get the human-readable name of a `QueryResultsFormat` instance using the `name` property. ```python >>> QueryResultsFormat.JSON.name 'SPARQL Results in JSON' ``` -------------------------------- ### Execute SPARQL SELECT Query with pyoxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to execute a SPARQL `SELECT` query using the `pyoxigraph.Store.query` method. This example initializes a store, adds a triple, and then queries for subjects, returning a list of `NamedNode` objects. ```Python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) [solution['s'] for solution in store.query('SELECT ?s WHERE { ?s ?p ?o }')] ``` -------------------------------- ### Python Example: QueryResultsFormat.iri Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Shows how to access the `iri` property of a `QueryResultsFormat` instance to get its canonical IRI. ```python >>> QueryResultsFormat.JSON.iri 'http://www.w3.org/ns/formats/SPARQL_Results_JSON' ``` -------------------------------- ### Dump pyoxigraph 0.2 SledStore content for migration Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/migration This code snippet demonstrates how to dump the content of a `SledStore` from pyoxigraph version 0.2 to a temporary N-Quads file. This is a necessary step before upgrading to pyoxigraph 0.3, where the on-disk storage system was rebuilt on top of RocksDB, replacing `SledStore` with `Store`. ```Python from pyoxigraph import SledStore store = SledStore('MY_STORAGE_PATH') with open('temp_file.nq', 'wb') as fp: store.dump(fp, "application/n-quads") ``` -------------------------------- ### Example: Parse Turtle String with pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io This example demonstrates how to parse a Turtle string using `pyoxigraph.parse`. It specifies the input string, the `RdfFormat.TURTLE`, and a `base_iri` for resolving relative IRIs, showing the resulting list of quads. ```Python list(parse(input=b'

"1" .', format=RdfFormat.TURTLE, base_iri="http://example.com/")) ``` -------------------------------- ### Python Example: QueryResultsFormat.media_type Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Demonstrates retrieving the IANA media type string for a `QueryResultsFormat` instance using the `media_type` property. ```python >>> QueryResultsFormat.JSON.media_type 'application/sparql-results+json' ``` -------------------------------- ### PyOxigraph Store.remove Method API and Example Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents and demonstrates the `remove` method of the PyOxigraph Store. This method removes a specified quad from the store. The example shows adding a quad, then removing it, and verifying the store is empty. ```APIDOC Store.remove(quad: Quad) Removes a quad from the store. Parameters: quad (Quad): The quad to remove. Returns: None Raises: OSError: If an error happens during the quad removal. ``` ```python store = Store() quad = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')) store.add(quad) store.remove(quad) list(store) ``` -------------------------------- ### Insert and Query RDF Triple with pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index This example demonstrates how to initialize a pyoxigraph Store, add a new RDF triple (subject, predicate, object), and then query the store using SPARQL to retrieve and print a specific value from the added triple. ```Python from pyoxigraph import * store = Store() ex = NamedNode('http://example/') schema_name = NamedNode('http://schema.org/name') store.add(Quad(ex, schema_name, Literal('example'))) for binding in store.query('SELECT ?name WHERE { ?name }'): print(binding['name'].value) ``` -------------------------------- ### Access pyoxigraph.Quad predicate property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example of accessing the `predicate` property of a `pyoxigraph.Quad` instance to retrieve the quad's predicate. ```python Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).predicate ``` -------------------------------- ### Access pyoxigraph.Triple Predicate Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example demonstrating how to access the `predicate` property of a pyoxigraph.Triple instance to retrieve its predicate component. ```Python >>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).predicate ``` -------------------------------- ### Get NQuads string representation of pyoxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to get the NQuads serialization of a `pyoxigraph.Store` instance using the `str()` function after adding a quad. ```python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) str(store) ``` -------------------------------- ### Access pyoxigraph.Quad subject property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example of accessing the `subject` property of a `pyoxigraph.Quad` instance to retrieve the quad's subject. ```python Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject ``` -------------------------------- ### Access pyoxigraph.Triple Subject Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example demonstrating how to access the `subject` property of a pyoxigraph.Triple instance to retrieve its subject component. ```Python >>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).subject ``` -------------------------------- ### Access pyoxigraph.Quad object property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example of accessing the `object` property of a `pyoxigraph.Quad` instance to retrieve the quad's object. ```python Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).object ``` -------------------------------- ### Access pyoxigraph.Quad triple property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example of accessing the `triple` property of a `pyoxigraph.Quad` instance to retrieve the quad's underlying triple. ```python Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).triple ``` -------------------------------- ### Check dataset support for RDF formats in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Illustrates how to use the `supports_datasets` property to determine if an RDF format supports RDF datasets in addition to RDF graphs. The example shows both `False` and `True` cases. ```Python RdfFormat.N_TRIPLES.supports_datasets RdfFormat.N_QUADS.supports_datasets ``` -------------------------------- ### Access pyoxigraph.Triple Object Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example demonstrating how to access the `object` property of a pyoxigraph.Triple instance to retrieve its object component. ```Python >>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).object > ``` -------------------------------- ### Python Example: QueryResultsFormat.from_media_type() Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Illustrates using `QueryResultsFormat.from_media_type()` to retrieve a format object from a media type string, including those with charset parameters. ```python >>> QueryResultsFormat.from_media_type("application/sparql-results+json; charset=utf-8") ``` -------------------------------- ### Get IANA media type for N-Triples format in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Demonstrates accessing the IANA media type for an RDF format using the `media_type` property. ```Python RdfFormat.N_TRIPLES.media_type ``` -------------------------------- ### Serialize RDF Triples to Turtle with Output Stream, Prefixes, and Base IRI Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io This example illustrates a more advanced serialization scenario. It shows how to serialize RDF triples to an in-memory `BytesIO` object, specifying the Turtle format, and including custom prefixes and a base IRI. The serialized content is then retrieved from the output buffer. ```Python >>> import io >>> output = io.BytesIO() >>> serialize([Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))], output, RdfFormat.TURTLE, prefixes={"ex": "http://example.com/"}, base_iri="http://example.com") >>> output.getvalue() b'@base .\n@prefix ex: .\n<> ex:p "1" .\n' ``` -------------------------------- ### Access pyoxigraph.Quad graph_name property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Example of accessing the `graph_name` property of a `pyoxigraph.Quad` instance to retrieve the quad's graph name. ```python Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).graph_name ``` -------------------------------- ### Get canonical IRI for N-Triples format in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Shows how to retrieve the canonical IRI for an RDF format, as defined by the Unique URIs for file formats registry, using the `iri` property. ```Python RdfFormat.N_TRIPLES.iri ``` -------------------------------- ### Get file extension for N-Triples format in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Shows how to retrieve the IANA-registered file extension for a specific RDF format using the `file_extension` property. ```Python RdfFormat.N_TRIPLES.file_extension ``` -------------------------------- ### Serialize pyoxigraph.Literal to String Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Demonstrates how the `str()` function serializes `pyoxigraph.Literal` objects into NTriples, Turtle, and SPARQL compatible string representations. Examples show literals with plain values, language tags, and explicit datatypes. ```Python str(Literal('example')) '"example"' str(Literal('example', language='en')) '"example"@en' str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer'))) '"11"^^' str(Literal(11)) '"11"^^' ``` -------------------------------- ### Access pyoxigraph.Literal Datatype Property Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Documents the `datatype` property of the `pyoxigraph.Literal` class, which returns the literal's datatype IRI as a `NamedNode`. It includes examples showing the datatype for plain strings, integers, and language-tagged strings. ```APIDOC property datatype Description: Returns the literal datatype IRI. Return type: NamedNode ``` -------------------------------- ### Check RDF-star support for RDF formats in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Demonstrates using the `supports_rdf_star` property to check if an RDF format supports RDF-star quoted triples. The example shows both `True` and `False` cases. ```Python RdfFormat.N_TRIPLES.supports_rdf_star RdfFormat.RDF_XML.supports_rdf_star ``` -------------------------------- ### Serialize a Simple RDF Triple to Turtle Format Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io This example demonstrates how to serialize a single RDF Triple object into the Turtle format using `pyoxigraph.serialize`. The function returns the serialized content as a bytes object. ```Python >>> serialize([Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))], format=RdfFormat.TURTLE) b' "1" .\n' ``` -------------------------------- ### Execute Basic SPARQL SELECT Query in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Demonstrates how to initialize a pyoxigraph Store, add a Quad, and execute a basic SPARQL SELECT query to retrieve solutions. ```python >>> store = Store() >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }')) ``` -------------------------------- ### Initialize pyoxigraph.Dataset and Serialize to N-Quads Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Demonstrates how to create an in-memory RDF dataset using `pyoxigraph.Dataset` and initialize it with quads. Also shows how to serialize the dataset to N-Quads format using the `str()` function. ```APIDOC class pyoxigraph.Dataset(quads=None) An in-memory RDF dataset. It can accommodate a fairly large number of quads (in the few millions). Use Store if you need on-disk persistence or SPARQL. Warning: It interns the strings and does not do any garbage collection yet: if you insert and remove a lot of different terms, memory will grow without any reduction. Parameters: quads (collections.abc.Iterable[Quad] or None, optional) – some quads to initialize the dataset with. ``` ```Python str(Dataset([Quad(NamedNode('http://example.com/s'), NamedNode('http://example.com/p'), NamedNode('http://example.com/o'), NamedNode('http://example.com/g'))])) ' .\n' ``` -------------------------------- ### pyoxigraph Store.query Method API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Detailed API documentation for the `query` method of the `pyoxigraph.Store` class, outlining all supported parameters, their types, descriptions, return values for different query types (ASK, CONSTRUCT, DESCRIBE, SELECT), and potential exceptions. ```APIDOC Parameters: query: str - the query to execute. base_iri: str or None, optional - the base IRI used to resolve the relative IRIs in the SPARQL query or None if relative IRI resolution should not be done. use_default_graph_as_union: bool, optional - if the SPARQL query should look for triples in all the dataset graphs by default (i.e. without GRAPH operations). Disabled by default. default_graph: NamedNode or BlankNode or DefaultGraph or list[NamedNode or BlankNode or DefaultGraph] or None, optional - list of the graphs that should be used as the query default graph. By default, the store default graph is used. named_graphs: list[NamedNode or BlankNode] or None, optional - list of the named graphs that could be used in SPARQL GRAPH clause. By default, all the store named graphs are available. substitutions: dict[Variable, NamedNode or BlankNode or Literal or Triple] or None, optional - dictionary of values variables should be substituted with. Substitution follows RDF-dev SEP-0007. custom_functions: dict[NamedNode, Callable[[NamedNode or BlankNode or Literal or Triple, ...], NamedNode or BlankNode or Literal or Triple or None]] or None, optional - dictionary of custom functions mapping function names to their definition. Custom functions takes for input some Terms and return a Term or None. Returns: bool for ASK queries. iterator of Triple for CONSTRUCT and DESCRIBE queries. iterator of QuerySolution for SELECT queries. Return type: QuerySolutions or QueryBoolean or QueryTriples Raises: SyntaxError: if the provided query is invalid. OSError: if an error happens while reading the store. ``` -------------------------------- ### APIDOC: pyoxigraph.Store.backup Method Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `backup` method of the `pyoxigraph.Store` class, which creates a database backup. Includes warnings about usage with in-memory databases and existing directories. ```APIDOC pyoxigraph.Store.backup(target_directory) Description: Creates database backup into the target_directory. After its creation, the backup is usable using Store constructor like a regular pyxigraph database and operates independently from the original database. Warnings: Backups are only possible for on-disk databases created by providing a path to Store constructor. Temporary in-memory databases created without path are not compatible with the backup system. An error is raised if the target_directory already exists. Note: If the target directory is in the same file system as the current database, the database content will not be fully copied but hard links will be used to point to the original database immutable snapshots. This allows cheap regular backups. ``` -------------------------------- ### APIDOC: pyoxigraph.Store.add Method Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `add` method of the `pyoxigraph.Store` class, used to add a single quad to the store. ```APIDOC pyoxigraph.Store.add(quad) Description: Adds a quad to the store. Parameters: quad (Quad): the quad to add. Return type: None Raises: OSError: if an error happens during the quad insertion. ``` -------------------------------- ### Execute ASK Query on PyOxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to perform an ASK query on a PyOxigraph Store. It initializes a store, adds a sample quad, and then executes an ASK query to check for the existence of any triples, returning a boolean result. ```python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) bool(store.query('ASK { ?s ?p ?o }')) ``` -------------------------------- ### PyOxigraph Store.remove_graph Method API and Example Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents and demonstrates the `remove_graph` method of the PyOxigraph Store. This method removes a specified graph from the store, noting that the default graph will be cleared, not removed. The example shows adding a quad to a named graph, then removing that graph, and verifying no named graphs remain. ```APIDOC Store.remove_graph(graph_name: NamedNode | BlankNode | DefaultGraph) Removes a graph from the store. The default graph will not be removed but just cleared. Parameters: graph_name (NamedNode | BlankNode | DefaultGraph): The name of the graph to remove. Returns: None Raises: OSError: If an error happens during the named graph removal. ``` ```python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) store.remove_graph(NamedNode('http://example.com/g')) list(store.named_graphs()) ``` -------------------------------- ### Dump PyOxigraph Store to TriG Format Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to initialize a PyOxigraph `Store`, add a simple quad, and then dump its content to a bytes buffer using the TriG format. The output shows the serialized RDF data. ```python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) store.dump(format=RdfFormat.TRIG) # Expected output: b' "1" .\n' ``` -------------------------------- ### pyoxigraph QuerySolution Class API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index Documents the `QuerySolution` class, representing a single SPARQL query solution. ```APIDOC QuerySolution: Represents a single SPARQL query solution. ``` -------------------------------- ### pyoxigraph.Store Class API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Comprehensive API documentation for the `pyoxigraph.Store` class, detailing its methods for managing RDF data, including adding, deleting, querying, and persisting quads and graphs. ```APIDOC Store: __init__ add() add_graph() backup() bulk_extend() bulk_load() clear() clear_graph() contains_named_graph() dump() extend() flush() load() named_graphs() optimize() quads_for_pattern() query() read_only() remove() remove_graph() update() ``` -------------------------------- ### Initialize Store for SPARQL INSERT DATA Update Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Initializes a PyOxigraph Store, typically as the first step before executing a SPARQL `INSERT DATA` update operation. This snippet sets up an empty store instance. ```python store = Store() ``` -------------------------------- ### APIDOC: pyoxigraph.Store Class Definition Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Defines the `pyoxigraph.Store` class, an RDF store based on RocksDB, detailing its constructor parameters, isolation level, and error handling. ```APIDOC class pyoxigraph.Store(path=None) Description: RDF store. It encodes a RDF dataset and allows to query it using SPARQL. It is based on the RocksDB key-value database. This store ensures the “repeatable read” isolation level: the store only exposes changes that have been “committed” (i.e. no partial writes) and the exposed state does not change for the complete duration of a read operation (e.g. a SPARQL query) or a read/write operation (e.g. a SPARQL update). Parameters: path (str or os.PathLike[str] or None, optional): The path of the directory in which the store should read and write its data. If the directory does not exist, it is created. If no directory is provided a temporary one is created and removed when the Python garbage collector removes the store. In this case, the store data are kept in memory and never written on disk. Raises: OSError: if the target directory contains invalid data or could not be accessed. ``` -------------------------------- ### PyOxigraph Store.dump API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Detailed API documentation for the `pyoxigraph.Store.dump` method, which serializes the store's content to a specified output or returns it as bytes. It covers parameters for output destination, RDF format, graph selection, prefixes, and base IRI, along with return types and potential exceptions. ```APIDOC pyoxigraph.Store.dump( output: IO[bytes] | str | os.PathLike[str] | None = None, format: RdfFormat | None = None, from_graph: NamedNode | BlankNode | DefaultGraph | None = None, prefixes: dict[str, str] | None = None, base_iri: str | None = None ) -> bytes | None Parameters: output (IO[bytes] | str | os.PathLike[str] | None, optional): The binary I/O object or file path to write to. If None, a bytes buffer is returned. format (RdfFormat | None, optional): The format of the RDF serialization. If None, guessed from file extension. from_graph (NamedNode | BlankNode | DefaultGraph | None, optional): The store graph from which to dump triples. Required if format does not support named graphs. prefixes (dict[str, str] | None, optional): Prefixes used in serialization if format supports it. base_iri (str | None, optional): Base IRI used in serialization if format supports it. Returns: bytes | None: bytes with serialization if output is None, None if output is set. Raises: ValueError: If format is not supported or from_graph is missing for non-named-graph syntax. OSError: If an error occurs during quad lookup or file writing. ``` -------------------------------- ### Get name for N-Triples format in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Shows how to retrieve the human-readable name of an RDF format using the `name` property. ```Python RdfFormat.N_TRIPLES.name ``` -------------------------------- ### pyoxigraph.Store.load() Method API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `load()` method for `pyoxigraph.Store`, used to import RDF serializations. It highlights that loads are transactional, supports various RDF formats (JSON-LD, N-Triples, N-Quads, Turtle, TriG, N3, RDF/XML), and can take input from bytes, string, I/O objects, or file paths. It also mentions parameters for base IRI and target graph, and potential `ValueError` for unsupported formats. ```APIDOC load(*input=None*, *format=None*, *\**, *path=None*, *base_iri=None*, *to_graph=None*) Description: Loads an RDF serialization into the store. Loads are applied in a transactional manner: either the full operation succeeds or nothing is written to the database. The bulk_load() method is also available for much faster loading of big files but without transactional guarantees. Beware, the full file is loaded into memory. Supported Formats: - JSON-LD 1.0 (RdfFormat.JSON_LD) - N-Triples (RdfFormat.N_TRIPLES) - N-Quads (RdfFormat.N_QUADS) - Turtle (RdfFormat.TURTLE) - TriG (RdfFormat.TRIG) - N3 (RdfFormat.N3) - RDF/XML (RdfFormat.RDF_XML) Parameters: input (bytes or str or IO[bytes] or IO[str] or None, optional): The str, bytes or I/O object to read from. For example, it could be the file content as a string or a file reader opened in binary mode with open('my_file.ttl', 'rb'). format (RdfFormat or None, optional): the format of the RDF serialization. If None, the format is guessed from the file name extension. path (str or os.PathLike[str] or None, optional): The file path to read from. Replaces the input parameter. base_iri (str or os.PathLike[str] or None, optional): The file path to read from. Replaces the input parameter. base_iri (str or None, optional): the base IRI used to resolve the relative IRIs in the file or None if relative IRI resolution should not be done. to_graph (NamedNode or BlankNode or DefaultGraph or None, optional): if it is a file composed of triples, the graph in which the triples should be stored. By default, the default graph is used. Return type: None Raises: ValueError: if the format is not supported. ``` -------------------------------- ### pyoxigraph QuerySolutions Class API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index Documents the `QuerySolutions` class, which represents a collection of SPARQL query solutions, including methods for serialization and accessing variables. ```APIDOC QuerySolutions: serialize(): Method to serialize query solutions. variables: Property to access variables of the query solutions. ``` -------------------------------- ### Get media type for N3 format in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/io Demonstrates how to access the `media_type` property of an `RdfFormat` enum member to retrieve its associated IANA media type. ```Python RdfFormat.N3.media_type ``` -------------------------------- ### Load RDF data in bulk into a PyOxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to use the `bulk_load` method of the `Store` class to load RDF data from a byte string in a specified format (e.g., TURTLE) into a named graph. It also shows how to inspect the loaded quads. ```APIDOC bulk_load(input, format, *, base_iri=None, to_graph=None) Parameters: base_iri (str or None, optional): the base IRI used to resolve the relative IRIs in the file or None if relative IRI resolution should not be done. to_graph (NamedNode or BlankNode or DefaultGraph or None, optional): if it is a file composed of triples, the graph in which the triples should be stored. By default, the default graph is used. Return type: None Raises: ValueError: if the format is not supported. SyntaxError: if the provided data is invalid. OSError: if an error happens during a quad insertion or if a system error happens while reading the file. ``` ```Python >>> store = Store() >>> store.bulk_load(input=b'

"1" .', format=RdfFormat.TURTLE, base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g")) >>> list(store) [ predicate= object=> graph_name=>] ``` -------------------------------- ### pyoxigraph RDF Store API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index Provides API details for the pyoxigraph Store class, which manages persistent RDF datasets, including methods for adding, removing, querying, and optimizing data. ```APIDOC Store: class add(): method add_graph(): method backup(): method bulk_extend(): method bulk_load(): method clear(): method clear_graph(): method contains_named_graph(): method dump(): method extend(): method flush(): method load(): method named_graphs(): method optimize(): method quads_for_pattern(): method query(): method read_only(): method remove(): method remove_graph(): method update(): method ``` -------------------------------- ### Handle CONSTRUCT Query Results in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/sparql.rst Documents the `QueryTriples` class within the `pyoxigraph` module, used to represent the set of triples returned by a SPARQL `CONSTRUCT` query. This class provides an iterable interface over the constructed triples. Its members are automatically documented. ```APIDOC class pyoxigraph.QueryTriples: # Members are automatically documented. ``` -------------------------------- ### pyoxigraph QueryTriples Class API for CONSTRUCT Results Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index Documents the `QueryTriples` class, used for handling triple results from SPARQL CONSTRUCT queries, including serialization. ```APIDOC QueryTriples: serialize(): Method to serialize triple query results. ``` -------------------------------- ### Handle SELECT Query Solutions in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/sparql.rst Documents the `QuerySolutions` class within the `pyoxigraph` module, designed to represent the collection of solutions returned by a SPARQL `SELECT` query. This class provides an iterable interface over the query results. Its members are automatically documented. ```APIDOC class pyoxigraph.QuerySolutions: # Members are automatically documented. ``` -------------------------------- ### pyoxigraph.CanonicalizationAlgorithm Class API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model API documentation for the `CanonicalizationAlgorithm` class in pyoxigraph, used for dataset canonicalization. ```APIDOC CanonicalizationAlgorithm ``` -------------------------------- ### pyoxigraph RDF Parsing and Serialization API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/io.rst API documentation for the `pyoxigraph` module, detailing functions for parsing and serializing RDF files and the `RdfFormat` class. ```APIDOC Module: pyoxigraph Functions: parse: Description: Function to parse RDF files. serialize: Description: Function to serialize RDF files. Classes: RdfFormat: Description: Class representing RDF formats. Members: All members of RdfFormat are documented. ``` -------------------------------- ### PyOxigraph Store bulk_load Method Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Loads an RDF serialization into the store, designed for high performance on large files without transactional guarantees. It supports various RDF formats and can read from input streams or file paths. ```APIDOC bulk_load(input=None, format=None, *, path=None, base_iri=None, to_graph=None) input: bytes or str or IO[bytes] or IO[str] or None, optional - The str, bytes or I/O object to read from. format: RdfFormat or None, optional - The format of the RDF serialization. If None, the format is guessed from the file name extension. path: str or os.PathLike[str] or None, optional - The file path to read from. Replaces the input parameter. Supported Formats: - JSON-LD 1.0 (RdfFormat.JSON_LD) - N-Triples (RdfFormat.N_TRIPLES) - N-Quads (RdfFormat.N_QUADS) - Turtle (RdfFormat.TURTLE) - TriG (RdfFormat.TRIG) - N3 (RdfFormat.N3) - RDF/XML (RdfFormat.RDF_XML) ``` -------------------------------- ### pyoxigraph QuerySolutions and QuerySolution API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/sparql Detailed API documentation for `pyoxigraph.QuerySolutions`, an iterator for SPARQL SELECT query results, and `pyoxigraph.QuerySolution`, a tuple representing a single result row. ```APIDOC class pyoxigraph.QuerySolutions Description: An iterator of QuerySolution returned by a SPARQL SELECT query Method: serialize(output: IO[bytes] | str | os.PathLike[str] | None = None, format: QueryResultsFormat | None = None) Description: Writes the query results into a file. It currently supports the following formats: * XML (QueryResultsFormat.XML) * JSON (QueryResultsFormat.JSON) * CSV (QueryResultsFormat.CSV) * TSV (QueryResultsFormat.TSV) It supports also some media type and extension aliases. For example, application/json could also be used for JSON. Parameters: output (IO[bytes] | str | os.PathLike[str] | None, optional): The binary I/O object or file path to write to. For example, it could be a file path as a string or a file writer opened in binary mode with open('my_file.ttl', 'wb'). If None, a bytes buffer is returned with the serialized content. format (QueryResultsFormat | None, optional): the format of the query results serialization. If None, the format is guessed from the file name extension. Return type: bytes or None Raises: ValueError: if the format is not supported. OSError: if a system error happens while writing the file. Property: variables Description: The ordered list of all variables that could appear in the query results Return type: list[Variable] class pyoxigraph.QuerySolution Description: Tuple associating variables and terms that are the result of a SPARQL SELECT query. It is the equivalent of a row in SQL. It could be indexes by variable name (Variable or str) or position in the tuple (int). Unpacking also works. ``` -------------------------------- ### Add a Named Graph to pyoxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Shows how to add a named graph to a `pyoxigraph.Store` instance and then list the named graphs to confirm the addition. ```python store = Store() store.add_graph(NamedNode('http://example.com/g')) list(store.named_graphs()) ``` -------------------------------- ### pyoxigraph.Store Class API Documentation Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/store.rst Documents the `Store` class from the `pyoxigraph` module, including all its public members. This class is likely used for managing RDF data. ```APIDOC Module: pyoxigraph Class: Store Description: Represents an RDF store for managing RDF data. Methods: (All members are documented as per :members: directive) Properties: (All members are documented as per :members: directive) ``` -------------------------------- ### APIDOC: pyoxigraph.Store.add_graph Method Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `add_graph` method of the `pyoxigraph.Store` class, used to add a named graph to the store. ```APIDOC pyoxigraph.Store.add_graph(graph_name) Description: Adds a named graph to the store. Parameters: graph_name (NamedNode or BlankNode or DefaultGraph): the name of the name graph to add. Return type: None Raises: OSError: if an error happens during the named graph insertion. ``` -------------------------------- ### Add a Quad to pyoxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Illustrates how to add a `Quad` object to a `pyoxigraph.Store` instance and then list its contents to verify the addition. ```python store = Store() store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) list(store) ``` -------------------------------- ### Dump PyOxigraph Store contents to a file Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Provides the API documentation for the `dump` method, which allows exporting the store's quads or triples into a file, supporting various RDF formats like JSON-LD, N-Triples, N-Quads, and Turtle. ```APIDOC dump(output=None, format=None, *, from_graph=None, prefixes=None, base_iri=None) Dumps the store quads or triples into a file. It currently supports the following formats: - JSON-LD 1.0 (RdfFormat.JSON_LD) - N-Triples (RdfFormat.N_TRIPLES) - N-Quads (RdfFormat.N_QUADS) - Turtle (RdfFormat.TURTLE) ``` -------------------------------- ### Extend pyoxigraph Store with RDF Quads Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store This snippet demonstrates how to add RDF quads to a `pyoxigraph.Store` instance using the `extend` method. It shows the creation of a `Store` object and the insertion of a single quad, followed by listing the store's contents. ```python >>> store = Store() >>> store.extend([Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))]) >>> list(store) [ predicate= object=> graph_name=>] ``` -------------------------------- ### Query Quads by Pattern in PyOxigraph Store Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Demonstrates how to add a quad to the store and then retrieve it using `quads_for_pattern()` by specifying a subject and using wildcards for predicate, object, and graph name. ```Python >>> store = Store() >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) >>> list(store.quads_for_pattern(NamedNode('http://example.com'), None, None, None)) [ predicate= object=> graph_name=>] ``` -------------------------------- ### Represent Single SELECT Query Solution in pyoxigraph Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/_sources/sparql.rst Documents the `QuerySolution` class within the `pyoxigraph` module, representing a single row or binding set from the results of a SPARQL `SELECT` query. This class allows access to individual variable bindings within a solution. Its members are automatically documented. ```APIDOC class pyoxigraph.QuerySolution: # Members are automatically documented. ``` -------------------------------- ### PyOxigraph Store.read_only Method API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `read_only` static method of the PyOxigraph Store. This method opens a store from disk in read-only mode, specifying the path to the primary read-write instance data. It returns the opened Store object and may raise an OSError. ```APIDOC Store.read_only(path: str) Opens a read-only store from disk. Undefined behavior if another process is writing the database. Parameters: path (str): Path to the primary read-write instance data. Returns: Store: The opened store. Raises: OSError: If the target directory contains invalid data or could not be accessed. ``` -------------------------------- ### Define pyoxigraph.Literal Class Constructor Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Documents the constructor for the `pyoxigraph.Literal` class, used to create RDF literals. It details the `value`, `datatype`, and `language` parameters, their types, and descriptions. It also notes potential `ValueError` for invalid language tags. ```APIDOC class pyoxigraph.Literal(value, *, datatype=None, language=None) Description: An RDF literal. Parameters: value (str or int or float or bool): the literal value or lexical form. datatype (NamedNode or None, optional): the literal datatype IRI. language (str or None, optional): the literal language tag. Raises: ValueError: if the language tag is not valid according to RFC 5646 (BCP 47). ``` -------------------------------- ### PyOxigraph Store.extend API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store API documentation for the `pyoxigraph.Store.extend` method, used to atomically add a collection of quads to the store. This method ensures transactional integrity, meaning all quads are added successfully or none are. ```APIDOC pyoxigraph.Store.extend(*quads: collections.abc.Iterable[Quad]) -> None Description: Adds atomically a set of quads to this store. Insertion is done in a transactional manner: either the full operation succeeds or nothing is written to the database. The bulk_extend() method is also available for much faster loading of a large number of quads but without transactional guarantees. Parameters: quads (collections.abc.Iterable[Quad]): The quads to add. Returns: None ``` -------------------------------- ### pyoxigraph.Store.flush() Method API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/store Documents the `flush()` method of the `pyoxigraph.Store` class, which ensures all buffered writes are saved to disk. It notes that flushes occur automatically in background threads but can be explicitly triggered. The method returns `None` and may raise an `OSError`. ```APIDOC flush() Description: Flushes all buffers and ensures that all writes are saved on disk. Flushes are automatically done using background threads but might lag a little bit. Return type: None Raises: OSError: if an error happens during the flush. ``` -------------------------------- ### Destructure pyoxigraph.Quad into components Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Shows how to easily destructure a `pyoxigraph.Quad` instance into its subject, predicate, object, and graph components using Python's tuple unpacking. ```python (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')) ``` -------------------------------- ### Destructure pyoxigraph.Triple into Components Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model Shows how to easily destructure a pyoxigraph.Triple instance into its subject, predicate, and object components using tuple assignment. ```Python >>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')) ``` -------------------------------- ### pyoxigraph RDF Parsing and Serialization API Reference Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/index Documents functions and classes for parsing RDF data from various formats and serializing RDF graphs into different representations within pyoxigraph. ```APIDOC parse(): function serialize(): function RdfFormat: class file_extension: property from_extension(): method from_media_type(): method iri: property media_type: property name: property supports_datasets: property supports_rdf_star: property ``` -------------------------------- ### pyoxigraph.Triple Class API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model API documentation for the `Triple` class in pyoxigraph, representing an RDF triple. ```APIDOC Triple: object predicate subject ``` -------------------------------- ### pyoxigraph.Dataset Class API Source: https://pyoxigraph.readthedocs.io/en/stable/index.html/model API documentation for the `Dataset` class in pyoxigraph, providing methods for managing RDF quads within a dataset. ```APIDOC Dataset: add() canonicalize() clear() discard() quads_for_graph_name() quads_for_object() quads_for_predicate() quads_for_subject() remove() ```