Skip to main content

One-line loading and saving to/from various file formats (csv, wav, pkl, json)

Project description

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

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

loadsave-0.0.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

loadsave-0.0.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file loadsave-0.0.3.tar.gz.

File metadata

  • Download URL: loadsave-0.0.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for loadsave-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ff5f2e3d2cd3873d882ae95413121fc50cd20c403f2ac15399ff0daad5c9414f
MD5 f1948df2cd31958b1dd92f1910da5aa0
BLAKE2b-256 93c63790a2ec832584d8b687dc3e2c07f6bfd2a2681d552ca474eac3078dd8ba

See more details on using hashes here.

File details

Details for the file loadsave-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: loadsave-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for loadsave-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 abbe76ad2752742d51885e075e650db1872ae5f0ce46bbe6094aff07527e238d
MD5 6646e288489c0400b688758d664ae228
BLAKE2b-256 0edd0b5b9a89842b912a74588d6572aeae1aec5b2e9bc15b86fcdc9f4fc613d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page