pyntree
Source code, roadmap, and more
Source code pyntree's source code is available at https://github.com/jvadair/pyntree. Roadmap ...
Getting started
What is pyntree?
Overview pyntree is a python package which allows you to easily and syntactically save your data...
A basic program with pyntree
Let's take a simple, yet practical example. Let's say you've written a web service, and need to ...
Terminology
Node A pythonic representation of data - each key in a dictionary is represented by a Node objec...
Installing
pyntree is available via pip: pip install pyntree That's it!
Supported file types and actions
File types
pyntree currently supports a plethora of file types, all of which can be encrypted: Pickle (defa...
The File object
The File object is a helper object to ensure data consistency across nodes. Each node holds a lin...
Changing the active file
To change the active file, you can use the switch_to_file method: File.switch_to_file(filename, ...
Reloading/retrieving the data from the file
To reload the data from the file, use the following method: File.reload() This method is only 1...
Encrypting a file
Encryption is a new feature as of 1.0.0! To use encryption, first type pip install pyntree[encry...
Basic Usage
Loading files/dictionaries
Syntax: Node(file_or_dictionary, **file_parameters) To load a file/dictionary, simply create ...
Getting nodes
Syntax: Node.get(*children) There are two ways to retrieve a child Node: root_node.get('chil...
Getting a value
Syntax: Node() pyntree takes a somewhat unique yet simple approach to getting the values stor...
Setting values
Syntax: Node.set(*children, value) To change a value or create a new node, you can use one of...
Saving
Syntax: Node.save(filename=None) Simply call the save method to save your data: root_node.sa...
Getting the names of the children
Syntax: Node._values To get a list of all of a Node's children, simply use the values propert...
Checking for a value
Syntax: Node.has(*names) To see if a Node has a child with a given name, use the has method: ...
Deleting a Node
Syntax: Node.delete(*children) The delete function can take either 0 or 1+ parameters: Node....
Getting the name of a Node
Syntax: Node._name Let's say you have a miscellaneous Node that got passed to a function some...
Math and object manipulation
Syntax: Node += val Math operations If you used pyndb, you probably had to do something like...
Getting the children
Syntax: Node._children The ._children property returns a list of Node objects (the children o...
Additional Features
The where() method
Syntax: Node.where(**kwargs) Let's say you have a lot of users, sorted by IDs. Now, you want ...
Converting back to a dictionary
Syntax: dict(Node) This is pretty straightforward, as shown above. The command will make a ne...
Node representation
Syntax: str(Node) # or repr(Node) str(Node) will return a string representation of the da...
Tips, Tricks, and Tidbits
Known limitations
Attempting to retrieve a name which is also a Node property will not work as intended (ex: _val...
Moving beyond a single flat file
For more complex projects, a flat-file database may not be the way to go. Here is one example of ...
How to fix pyntree installing as UNKNOWN-0.0.0
pip install --upgrade pip wheel setuptools