Skip to main content

Datastore

Currently supported file structures: CSV WAV JSON PICKLE

Python module which loads and saves data structures based on the file extension.

Dependencies

  • Python3 (and native libraries)
    • json
    • csv
    • wave
    • struct
    • importlib
    • os
    • pickle

Installation

pip install loadsave

Usage

import loadsave

data = loadsave.load(filename)
... manipulating data ...
loadsave.save(data, filename)

Saving data can be a bit unintuitive.

  • csv requires data to be a list of dictionaries
  • wav requires data to be a tuple or list of the form (y,sr) exactly how it would be returned by load('example.wav')

Objective

This module attempts to follow a generic procedure for reading and writing common data storage formats using only the file extension for guidance.

The motivation here is as follows; Most of the time, the most generic approach to opening a file will work. It's may not be the most computationaly efficient way, but if loading time is not a bottleneck for your workflow, you might as well spend your time manipulating the data as opposed figuring out how to load it into python. The goal of Datastore is to make implementing these generic approaches as fast as possible. If it doesn't work, well at least you didn't waste much time. Otherwise, you just skipped a monotonous task and can get on with real work.

Example

import loadsave

d = [{'id': [1,2,3,4],'otherID':[4,3,2,1]}]

# save this dict as a pickle
loadsave.save(d, 'test.pkl')

'test.pkl' can be replaced with 'test.json', or 'test.csv'. Attempting to save it to 'test.wav' will return an error, because d is not an acceptable format for an audio waveform.

However, if d = [0,1,2,3,4] you could call loadsave.save((d,44100),'test.wav'). csvs require a list of dictionaries, so trying to save this as a csv will fail

File Types

CSV

  • This is just a wrapper for csv.DictReader() / csv.DictWritter()
  • The data must be a list of dictionaries

WAV

  • Restricted to 16-bit audio
  • Can handle stereo/multi-channel waveforms
  • Data must be a list or tuple of the form (waveform, samplerate), just like it is provided from loadsave.load('example.wav')

PICKLE

  • This should work with any data structure in python.

JSON

  • Can hanle dict, list, str, int, float, bool, and None

Release files for loadsave 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loadsave 0.0.3
File Size Uploaded
loadsave-0.0.3.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loadsave 0.0.3
File Interpreter ABI Platform
loadsave-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / loadsave-0.0.3.tar.gz

Download URL loadsave-0.0.3.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ff5f2e3d2cd3873d882ae95413121fc50cd20c403f2ac15399ff0daad5c9414f
BLAKE2b-256 checksum
How to use checksums
93c63790a2ec832584d8b687dc3e2c07f6bfd2a2681d552ca474eac3078dd8ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.0

Release files / loadsave-0.0.3-py3-none-any.whl

Download URL loadsave-0.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abbe76ad2752742d51885e075e650db1872ae5f0ce46bbe6094aff07527e238d
BLAKE2b-256 checksum
How to use checksums
0edd0b5b9a89842b912a74588d6572aeae1aec5b2e9bc15b86fcdc9f4fc613d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page