fsstore

Dict-like objects for file I/O
Download

fsstore Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • startling
  • Publisher web site:
  • http://cytoplasm.somethingsido.com

fsstore Tags


fsstore Description

fsstore is a Python module that provides an easy way to use dict-like objects for file I/O.fsstore isn't intended to be a replacement for databases. You can't easily (efficiently) search for objects with x attribute. There are only two types of objects -- strings and dicts of strings, which map to files and directories.Instead, it's supposed to be an alternative to full-fledged databases for when you only need key-value pairs with a tiny api.It's pretty simple:# -*- coding: utf-8 -*-from fsstore import Store# initialize a Store in a directory called "testing"s = Store("testing")# save a string to a files = "Hello, fsstore."# create an empty directorys = {}# create a non-empty directorys = { "one": "1, I, i, one", "two": "2, II, ii, two",}# update a directorys.update({ "first_dir_file": "hello, world."})# get the path of a file or directory (it doesn't necessarily have to exist yet)s.get_path("first_file")# >> "testing/first_file"# get a file object, in case you want it for iterating overwith s.get_file("first_file", "r") as f: for line in f: print line# or if you want to use a function that requires a file-like objectimport jsonwith s.get_file("second_file", "w") as f: json.dump(, f, indent=4)# a word of caution -- always encode `unicode` objects before storing thems = { u"α".encode("utf-8"): "alpha", u"β".encode("utf-8"): "beta", u"γ".encode("utf-8"): "gamma",}And here's what the directory tree looks like after all of that:testing├── first_dir│ └── first_dir_file├── first_file├── second_dir│ ├── one│ └── two├── second_file└── unicode ├── α ├── β └── γInstallationYou can install fsstore from PyPI:pip install fsstoreor directly from this git repository:pip install git+https://github.com/startling/fsstore.gitProduct's homepage


fsstore Related Software