Skip to main content

Store and cache things anywhere

Project description

anystore on pypi Python test and package pre-commit Coverage Status GPL-3.0 License

anystore

Store anything anywhere. anystore provides a high-level storage and retrieval interface for various supported store backends, such as redis, sql, file, http, cloud-storages and anything else supported by fsspec.

Think of it as a key -> value store, and anystore acts as a cache backend. And when keys become filenames and values become byte blobs, anystore becomes actually a file-like storage backend – but always with the same and interchangeable interface.

Why?

In our several data engineering projects we always wrote boilerplate code that handles the featureset of anystore but not in a reusable way. This library shall be a stable foundation for data wrangling related python projects.

Examples

Base cli interface:

anystore -i ./local/foo.txt -o s3://mybucket/other.txt

echo "hello" | anystore -o sftp://user:password@host:/tmp/world.txt

anystore -i https://investigativedata.io > index.html

anystore --store sqlite:///db keys <prefix> 

anystore --store redis://localhost put foo "bar"

anystore --store redis://localhost get foo  # -> "bar"

Use in your applications:

from anystore import smart_read, smart_write

data = smart_read("s3://mybucket/data.txt")
smart_write(".local/data", data)

Simple cache example via decorator:

@anycache is used for api view cache in ftmq-api

from anystore import get_store, anycache

cache = get_store("redis://localhost")

@anycache(store=cache, key_func=lambda q: f"api/list/{q.make_key()}", ttl=60)
def get_list_view(q: Query) -> Response:
    result = ... # complex computing will be cached
    return result

Mirror file collections:

from anystore import get_store

source = get_store("https://example.org/documents/archive1")  # directory listing
target = get_store("s3://mybucket/files", backend_config={"client_kwargs": {
    "aws_access_key_id": "my-key",
    "aws_secret_access_key": "***",
    "endpoint_url": "https://s3.local"
}})  # can be configured via ENV as well

for path in source.iterate_keys():
    # streaming copy:
    with source.open(path) as i:
        with target.open(path, "wb") as o:
            i.write(o.read())

Documentation

Find the docs at investigativedata.io/docs/anystore

Used by

Development

This package is using poetry for packaging and dependencies management, so first install it.

Clone this repository to a local destination.

Within the repo directory, run

poetry install --with dev

This installs a few development dependencies, including pre-commit which needs to be registered:

poetry run pre-commit install

Before creating a commit, this checks for correct code formatting (isort, black) and some other useful stuff (see: .pre-commit-config.yaml)

testing

anystore uses pytest as the testing framework.

make test

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

anystore-0.1.13.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

anystore-0.1.13-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file anystore-0.1.13.tar.gz.

File metadata

  • Download URL: anystore-0.1.13.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.10.11-amd64

File hashes

Hashes for anystore-0.1.13.tar.gz
Algorithm Hash digest
SHA256 d5ed82fa4143ab696f7eda39d7b3d131d797e197ea0b609597f5c16bf2ea9731
MD5 e0f23a46de4dace3c48e764f37285002
BLAKE2b-256 72b2df3bbfcb339d8e04dfd0234cefe227ee039e6874b682941788f31c7706e7

See more details on using hashes here.

File details

Details for the file anystore-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: anystore-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.10.11-amd64

File hashes

Hashes for anystore-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ab98e6a720ce0c9982abad5da4e39667332a3a93d23eec0164b4b37962acf88c
MD5 7586c07690092b389818724ffea9002d
BLAKE2b-256 cba56ebf81927dffecd514ea77026c2c536005fb6f71763f1cef6617e7203d24

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