Skip to main content

Python COTTAS library for compressing and querying RDF.

Project description

pycottas

License Latest PyPI version Python Version PyPI status Documentation Status

pycottas is a library for working with compressed RDF files in the COTTAS format. COTTAS stores triples in a triple table in Apache Parquet. It is built on top of DuckDB and provides an HDT-like interface.

Features :sparkles:

  • Compression and decompression of RDF files.
  • Querying COTTAS files with triple patterns.
  • RDFLib backend for querying COTTAS files with SPARQL.
  • Supports named graphs (quads).
  • Can be used as a library or via command line.

Documentation :bookmark_tabs:

Read the documentation.

Getting Started :rocket:

PyPi is the fastest way to install pycottas:

pip install pycottas

We recommend to use virtual environments to install pycottas.

import pycottas
from rdflib import Graph, URIRef

pycottas.rdf2cottas('my_file.ttl', 'my_file.cottas', index='spo')
res = pycottas.search('my_file.cottas', '?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o')
print(res)
pycottas.cottas2rdf('my_file.cottas', 'my_file.nt')

# COTTASDocument class for querying with triple patterns
cottas_doc = pycottas.COTTASDocument('my_file.cottas')
# It is possible to create a document from multiple COTTAS files matching a glob pattern
cottas_doc = pycottas.COTTASDocument('test/*.cottas')
# the triple pattern can be a string or a tuple
res = cottas_doc.search('?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o')
# limit and offset are optional
res = cottas_doc.search((None, URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), None), limit=10, offset=20)
print(res)

# COTTASStore class for querying with SPARQL
graph = Graph(store=pycottas.COTTASStore("my_file.cottas"))
res = graph.query("""
  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
  SELECT DISTINCT ?s ?o WHERE {
    ?s rdf:type ?o .
  } LIMIT 10""")
for row in res:
    print(row)

To execute via command line check the docs.

License :unlock:

pycottas is available under the Apache License 2.0.

Author & Contact :mailbox_with_mail:

Universidad Politécnica de Madrid.

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

pycottas-1.0.0.tar.gz (443.9 kB view details)

Uploaded Source

Built Distribution

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

pycottas-1.0.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file pycottas-1.0.0.tar.gz.

File metadata

  • Download URL: pycottas-1.0.0.tar.gz
  • Upload date:
  • Size: 443.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pycottas-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8a54e40ff7cce1eeb9919c3fe8a263be4e2197966856c88395e30fc036daab15
MD5 0c096b5a95cdd2bc9dee200fe339a10c
BLAKE2b-256 f3bc2b7d8a949ae370d7141ba60cb5e0c72748a39988a6b1cb71008be924b15d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycottas-1.0.0.tar.gz:

Publisher: pypi-publish.yml on arenas-guerrero-julian/pycottas

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

File details

Details for the file pycottas-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycottas-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pycottas-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b92e4458018c0c810adeca0c518928cc2ef9666422079a1a19987af26c4a024
MD5 3fd9fcc0c40a79cd5ed3d5b416ae9402
BLAKE2b-256 6e0027ebd07fd2ea40789c326bfed46d8333e1758772bae5142d6a83e3d21043

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycottas-1.0.0-py3-none-any.whl:

Publisher: pypi-publish.yml on arenas-guerrero-julian/pycottas

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