Skip to main content

Python client for the SewerRat API

Project description

Python interface to the SewerRat API

Unit tests Documentation PyPI-Server

Pretty much as it says on the tin: provides a Python client for the API of the same name. It is assumed that the users of the sewerrat client and the SewerRat API itself are accessing the same shared filesystem; this is typically the case for high-performance computing clusters in scientific institutions. To demonstrate, let's spin up a mock SewerRat instance:

import sewerrat as sr
_, url = sr.start_sewerrat()

Let's mock up a directory of metadata files:

import tempfile
import os

mydir = tempfile.mkdtemp()
with open(os.path.join(mydir, "metadata.json"), "w") as handle:
    handle.write('{ "first": "foo", "last": "bar" }')

os.mkdir(os.path.join(mydir, "diet"))
with open(os.path.join(mydir, "diet", "metadata.json"), "w") as handle:
    handle.write('{ "fish": "barramundi" }')

We can then easily register it via the register() function. Similarly, we can deregister this directory with deregister(mydir).

# Only indexing metadata files named 'metadata.json'.
sr.register(mydir, names=["metadata.json"], url=url)

To search the index, we use the query() function to perform free-text searches. This does not require filesystem access and can be done remotely.

sr.query(url, "foo")
sr.query(url, "bar%") # partial match to 'bar...'
sr.query(url, "bar% AND foo") # boolean operations
sr.query(url, "fish:bar%") # match in the 'fish' field

We can also search on the user, path components, and time of creation:

sr.query(url, user="LTLA") # created by myself
sr.query(url, path="diet/") # path has 'diet/' in it

import time
sr.query(url, after=time.time() - 3600) # created less than 1 hour ago

Once we find a file of interest from a registered directory, we can retrieve its metadata, or other files in the same directory, or the entire directory itself:

sr.retrieve_metadata(mydir + "/metadata.json", url)
sr.list_files(mydir, url)
sr.retrieve_file(mydir + "/diet/metadata.json", url)
sr.retrieve_directory(mydir, url)

Check out the API documentation for more details on each function. For the concepts underlying the SewerRat itself, check out the repository for a detailed explanation.

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

sewerrat-0.2.1.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

SewerRat-0.2.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file sewerrat-0.2.1.tar.gz.

File metadata

  • Download URL: sewerrat-0.2.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for sewerrat-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9cc5bddb67c34829a56ad7bfd1d82075996f7ee9a1de69c035af48b1395905e7
MD5 a4cda252e92089cf0c52b8846346c17b
BLAKE2b-256 060652553e4c034a5797d62c3ed57df11299848aec7039a3a4f0fe7c2d041ce4

See more details on using hashes here.

File details

Details for the file SewerRat-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: SewerRat-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for SewerRat-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f92060b6250afe252f48af43844a1ba8936e6f953e038c7369eb32f210d14f9
MD5 b4e3d28b7b228866c50c6f46a891d2f6
BLAKE2b-256 eb410736f3b1975cefe763bedfa35e32d20566e31898b37a6002afb823719765

See more details on using hashes here.

Supported by

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