Skip to main content

Store and cache things anywhere

Project description

Docs anystore on pypi PyPI Downloads PyPI - Python Version Python test and package pre-commit Coverage Status AGPLv3+ License Pydantic v2

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://dataresearchcenter.org > 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:

Use case: @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:
            while chunk := i.read(8192):
                o.write(chunk)

Documentation

Find the docs at docs.investigraph.dev/lib/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

License and Copyright

anystore, (C) 2024 investigativedata.io

anystore, (C) 2025 investigativedata.io, Data and Researc Center – DARC

anystore is licensed under the AGPLv3 or later license.

Prior to version 0.3.0, anystore was released under the GPL-3.0 license.

see NOTICE and LICENSE

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-1.1.8.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

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

anystore-1.1.8-py3-none-any.whl (73.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anystore-1.1.8.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.0 CPython/3.13.5 Linux/6.12.74+deb13+1-amd64

File hashes

Hashes for anystore-1.1.8.tar.gz
Algorithm Hash digest
SHA256 bae52548ada03cf7484ae8725cd448ec8a113e9c3f55cb221e1a83c5a820ccb3
MD5 a7fdba3d68ed057c5f3f105b9cf4dfe2
BLAKE2b-256 7fd9535dc158d568d01138f93020ff1c711a170b9d3a5b5dfc93b35a8be0ef9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: anystore-1.1.8-py3-none-any.whl
  • Upload date:
  • Size: 73.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.0 CPython/3.13.5 Linux/6.12.74+deb13+1-amd64

File hashes

Hashes for anystore-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7342278f0d831efd0961c4e3825d5ce4ef4c1d24088153f9c9f0ce39e9b7a1aa
MD5 2d1b5c99168737a226cb685037b308a9
BLAKE2b-256 551c4212f9fea5b5b19b8666327652883221e54f5a5c4eb6aec2567f66fce510

See more details on using hashes here.

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