Skip to main content

dictature -- A generic wrapper around dict-like interface with mulitple backends

Project description

Dictature

Make a Python dictionary out of anything. A wrapper for Python's dictionary with multiple backends. Thread-safe, supports multiple backends, and allows for transformers to change how the data is stored.

SQLite, directory, webdav, and more backends are supported, and you can easily create your own backend.

PyPI version

Installation

pip install dictature

Dictature usage

This package also includes a class that allows you to use your SQLite db or any backend as a Python dictionary:

from dictature import Dictature
from dictature.backend import DictatureBackendDirectory, DictatureBackendSQLite

# will use/create the db directory
# dictionary = Dictature(DictatureBackendDirectory('test_data'))
# will use/create the db file
dictionary = Dictature(DictatureBackendSQLite('test_data.sqlite3'))

# will create a table db_test and there a row called foo with value bar
dictionary['test']['foo'] = 'bar'

# also support anything that can be jsonized
dictionary['test']['list'] = ['1', 2, True]
print(dictionary['test']['list'])  # prints ['1', 2, True]

# or anything, really (that can be serialized with pickle)
from threading import Thread
dictionary['test']['thread'] = Thread
print(dictionary['test']['thread'])  # prints <class 'threading.Thread'>

# and deleting
del dictionary['test']['list']  # deletes the record
del dictionary['test']  # drops whole table

Currently, the following backends are supported:

  • DictatureBackendDirectory: stores the data in a directory as json files
  • DictatureBackendSQLite: stores the data in a SQLite database
  • DictatureBackendMISP: stores the data in a MISP instance
  • DictatureBackendWebdav: stores data in a WebDav share as files
  • DictatureBackendS3: stores data in an S3 bucket
  • DictatureBackendMySQL: stores data in a MySQL database
  • DictatureBackendBaserow: stores data in a Baserow database

Transformers

You can also use transformers to change how the values are stored. E.g. to encrypt data, you can use the AESTransformer (which requires the pycryptodome package):

from dictature import Dictature
from dictature.backend import DictatureBackendDirectory
from dictature.transformer.aes import AESTransformer

name_transformer = AESTransformer('password1', True)
value_transformer = AESTransformer('password2', False)

dictionary = Dictature(
    DictatureBackendSQLite('test_data.sqlite3'),
    name_transformer=name_transformer,
    value_transformer=value_transformer
)

Currently, the following transformers are supported:

  • AESTransformer: encrypts/decrypts the data using AES
  • HmacTransformer: signs the data using HMAC or performs hash integrity checks
  • GzipTransformer: compresses given data
  • PassthroughTransformer: does nothing
  • PipelineTransformer: chains multiple transformers

Testing

All tests are located inside tests folder. However, by default only backends that do not require any additonal service running are tested. If you want to test all the self-hostable backends, either setup environment variables for access or run run_tests_with_backends.py script that will create temporary backends for you via podman-compose.

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

dictature-1.0.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

dictature-1.0.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file dictature-1.0.0.tar.gz.

File metadata

  • Download URL: dictature-1.0.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dictature-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fdebc74c2ee23425009bcdc292adf98e1d2204f34976be47ca99602a09b2396c
MD5 4c73175dfc0f4bc5cace5b988ff107b3
BLAKE2b-256 417fda3dc55a3d88407ffdcff720152503bb7934846a26ef4277d4a619c84a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for dictature-1.0.0.tar.gz:

Publisher: pypi-deploy.yml on esoadamo/dictature

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dictature-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dictature-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dictature-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c92e6da79201a2aa3b9dea6f2a2975afcb2332478095f01a2f476a0975f519cf
MD5 a5c969f65d5deb6b0e0e67676405dfd7
BLAKE2b-256 29dc8fb0a62723d562030e49812be6e63a6d1bf7b1b60d26fd983b67c91f4903

See more details on using hashes here.

Provenance

The following attestation bundles were made for dictature-1.0.0-py3-none-any.whl:

Publisher: pypi-deploy.yml on esoadamo/dictature

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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