Skip to main content

timestamped JSON objects.

Project description

OBJ is a package that provides an Object class that can save/load from disk, thus providing persistence to objects.

Files are saved with a timestamp in their filenames, so that searching in a time related manner becomes possible.

Modules are provided to query saved objects as well as to run objects with a thread to manage their state.

OBJ has a “no-clause MIT license” that should be the most liberal free license you can get at the year 2018.

variables

cfg = Config()

cfg.workdir = os.path.join(os.path.expanduser(“~”), “.obj”)

you can change cfg.workdir if you need to save your objects in an other directory then the default directory.

methods

cache(path: str) → Object

load this object from cache or read it from disk.

clear() → None

clear the ready flag.

format(keys=[], skip=[], nokeys=False, reverse=False) → str

return a displayable string from a list of attributes.

grep(val: str) → Object

return a new Object with the values that match provided val argument.

isSet() → bool

check whether ready flag is set.

load(path: str, force=False, skip=[], full=True) → Object

load a json file into this object. use skip as a list of keys to skip.

loads(jsonstring: str) → Object

update with deconstructed (dict) json string.

merge(obj: Object) → Object

merge an object into this on, only set keys that are already present.

nice() → str

return a nicyfied JSON dump.

prepare() → str

prepare the object and return a string containing the “data” part.

pure() → str

return a sliced (no _ keys), indent=4, sort_key is True, json dump

read(path: str) → str

read a json dump from given path, returning the json string with comments stripped.

ready() → bool

signal this object as “ready”.

register(key, val, force=False) → None

register key, value - throw an exception if key is already set.

save(path=”“) → str

save a static (fix filepath) version of this object.

search(name: str) → Object

search this objects keys skipping keys that start with “_”.

sync(path=’‘) → str

sync to disk using provided/created path. this sync() method does the real saving to disk.

upgrade(input: dict) → None

upgrade this object with a dictionary, only setting attributes if they do not exist.

wait(timeout=None) → list

wait for this object’s ready flag and join all thread that have been started in handling this object,

exceptions

class ESET(Exception):

key is already set.

class ENOJSON(Exception):

the provided string is not JSON.

class EBORDER(Exception):

attemped to write outside of the workdir.

class EFILENAME(Exception):

provided string is not a filename.

Project details


Release history Release notifications

This version

3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for obj, version 3
Filename, size File type Python version Upload date Hashes
Filename, size obj-3.tar.gz (14.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page