py2store

py2store: tools to create simple and consistent interfaces to complicated and varied data sources.

The core has moved to the dol package (Data Object Layer); py2store keeps the original names, re-exports them, and keeps the local-file stores that still live here. A store is a MutableMapping whose keys and values are transformed on the way in and out, so that files, zip archives or databases are read and written like a dict.

Main entry points:

  • LocalTextStore, LocalBinaryStore, LocalPickleStore, LocalJsonStore: the files under a root directory as a dict

  • QuickStore: the pickle store with a temporary default root and directories created on write

  • wrap_kvs, filt_iter, cached_keys: transform a store’s keys, values or iteration (from dol.trans)

  • kvhead, ihead: peek at the first items of a store or an iterable

>>> from py2store import kvhead
>>> kvhead({'a': 1, 'b': 2})
('a', 1)

Functions

ihead(store[, n])

Get the first item of an iterable, or a list of the first n items.

kvhead(store[, n])

Get the first (key, value) item of a store, or a list of the first n items.

py2store.ihead(store, n=1)[source]

Get the first item of an iterable, or a list of the first n items.

With n=1 the item itself is returned (None if the iterable is empty); otherwise a list of at most n items.

>>> ihead(iter('abc'))
'a'
>>> ihead('abc', 2)
['a', 'b']
>>> ihead(iter('')) is None
True
py2store.kvhead(store, n=1)[source]

Get the first (key, value) item of a store, or a list of the first n items.

With n=1 the item itself is returned (None if the store is empty); otherwise a list of at most n items, in the store’s iteration order.

>>> kvhead({'a': 1, 'b': 2})
('a', 1)
>>> kvhead({'a': 1, 'b': 2}, 5)
[('a', 1), ('b', 2)]
>>> kvhead({}) is None
True

Modules

access

Utils to load stores from store specifications.

appendable([store_cls, return_keys, ...])

Makes a new class with append (and consequential extend) methods

base

Forwards to dol.base:

caching

Forwards to dol.caching:

dig

Forwards to dol.dig:

errors

Forwards to dol.errors:

ext

py2store Extensions, Add-ons, etc.

filesys

Forwards to dol.filesys:

key_mappers

key mapping

misc

Functions to read from and write to misc sources.

mixins

Forwards to dol.mixins:

my

functionalities meant to be configurable

naming

Forwards to dol.naming:

parse_format

Modified from https://github.com/r1chardj0n3s/parse

paths

Forwards to dol.paths:

persisters

base persisters -- now all forwarding to separate libraries

serializers

a package of serializers

signatures

Forwards to dol.signatures:

slib

Data Object Layers for a few standard libs.

sources

Forwards to dol.sources:

stores

a package of various stores

test

test files

trans

Forwards to dol.trans:

util

Forwards to dol.util:

utils

general utils