Skip to main content

Appendable key-value storage

Project description

Build Status Version Status

Key-value byte store with appendable values

Partd stores key-value pairs. Values are raw bytes. We append on old values.

Partd excels at shuffling operations.

Operations

PartD has two main operations, append and get.

Example

  1. Create a Partd backed by a directory:

    >>> import partd
    >>> p = partd.File('/path/to/new/dataset/')
  2. Append key-byte pairs to dataset:

    >>> p.append({'x': b'Hello ', 'y': b'123'})
    >>> p.append({'x': b'world!', 'y': b'456'})
  3. Get bytes associated to keys:

    >>> p.get('x')         # One key
    b'Hello world!'
    
    >>> p.get(['y', 'x'])  # List of keys
    [b'123456', b'Hello world!']
  4. Destroy partd dataset:

    >>> p.drop()

That’s it.

Implementations

We can back a partd by an in-memory dictionary:

>>> p = Dict()

For larger amounts of data or to share data between processes we back a partd by a directory of files. This uses file-based locks for consistency.:

>>> p = File('/path/to/dataset/')

However this can fail for many small writes. In these cases you may wish to buffer one partd with another, keeping a fixed maximum of data in the buffering partd. This writes the larger elements of the first partd to the second partd when space runs low:

>>> p = Buffer(Dict(), File(), available_memory=2e9)  # 2GB memory buffer

You might also want to have many distributed process write to a single partd consistently. This can be done with a server

  • Server Process:

    >>> p = Buffer(Dict(), File(), available_memory=2e9)  # 2GB memory buffer
    >>> s = Server(p, address='ipc://server')
  • Worker processes:

    >>> p = Client('ipc://server')  # Client machine talks to remote server

Encodings and Compression

Once we can robustly and efficiently append bytes to a partd we consider compression and encodings. This is generally available with the Encode partd, which accepts three functions, one to apply on bytes as they are written, one to apply to bytes as they are read, and one to join bytestreams. Common configurations already exist for common data and compression formats.

We may wish to compress and decompress data transparently as we interact with a partd. Objects like BZ2, Blosc, ZLib and Snappy exist and take another partd as an argument.:

>>> p = File(...)
>>> p = ZLib(p)

These work exactly as before, the (de)compression happens automatically.

Common data formats like Python lists, numpy arrays, and pandas dataframes are also supported out of the box.:

>>> p = File(...)
>>> p = NumPy(p)
>>> p.append({'x': np.array([...])})

This lets us forget about bytes and think instead in our normal data types.

Composition

In principle we want to compose all of these choices together

  1. Write policy: Dict, File, Buffer, Client

  2. Encoding: Pickle, Numpy, Pandas, …

  3. Compression: Blosc, Snappy, …

Partd objects compose by nesting. Here we make a partd that writes pickle encoded BZ2 compressed bytes directly to disk:

>>> p = Pickle(BZ2(File('foo')))

We could construct more complex systems that include compression, serialization, buffering, and remote access.:

>>> server = Server(Buffer(Dict(), File(), available_memory=2e0))

>>> client = Pickle(Snappy(Client(server.address)))
>>> client.append({'x': [1, 2, 3]})

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

partd-1.4.1.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

partd-1.4.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file partd-1.4.1.tar.gz.

File metadata

  • Download URL: partd-1.4.1.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for partd-1.4.1.tar.gz
Algorithm Hash digest
SHA256 56c25dd49e6fea5727e731203c466c6e092f308d8f0024e199d02f6aa2167f67
MD5 40275e1ee203757c997e935485d47888
BLAKE2b-256 a539d13decd99a0d7e4bdde3ede536237ddf08c8c69bcedb4784fa26de649b47

See more details on using hashes here.

Provenance

File details

Details for the file partd-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: partd-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for partd-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27e766663d36c161e2827aa3e28541c992f0b9527d3cca047e13fb3acdb989e6
MD5 aef2b747e396a7e6d23fad435fa39781
BLAKE2b-256 118ab7a58e208b144a7315208a0dd627e23f5f50b47fa89c2924bb2e9238ecfb

See more details on using hashes here.

Provenance

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