Skip to main content

Filesystem-like hierarhy of objects and it's namespace

Project description

pyNamespace

pyNamespace is an Application Framework supporting creation of the in-application data storage, simulating organization and behavior of the Unix filesystem graph. You can create "directories" and data objects. Refer those directories and data using Unix-like path. Also, you can create internal links between an objects and link one data object to more than one "directory".

Creation of a namespace

from pyNamespace import *
ns = Namespace()

After you import pyNamespace module, you shall create an object of type Namespace. The "filesystem" root - "/" will be created automatically.

Reading and writing into a namespace

from pyNamespace import *
ns = Namespace()
ns.set("home/answer", 42)
print(ns.get("home/answer"))

.set and .get methods will store and read objects from Namespace. Parameters for .set will be the path and a value which will be stored at that path. For .get it'll be a path, from which value will be retrieved.

Removing objects from namespace

from pyNamespace import *
ns = Namespace()
ns.set("home/answer", 42)
ns.rm("home/answer")

.rm with path parameter will remove an object from the namespace. .rm also removes all "orphan" (nodes which do not have an incoming connections) nodes from the graph.

Refer one node to another in the namespace.

There are two types of the references Soft-reference assumes that the object will be created in the graph, which will have a reference to another object. Method .get will recognize the reference and return the value of the original (source) object. Hard-reference will actually link source object with destination object in the graph.

.link method will create a "soft-link" and .ref will create a hard-reference.

from pyNamespace import *

ns = Namespace()
ns.set("home/answer", 42)
print(ns.link("home/answer", "etc/answer"))
print(ns.get("etc/answer"))

This is an example of the soft-reference.

from pyNamespace import *

ns = Namespace()
ns.set("home/answer", 41)
ns.ref("home/answer", "etc")
ns.set("home/answer", 42)

This is an example of the hard-reference

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

pyNamespace-0.0.1.tar.gz (17.6 kB view hashes)

Uploaded Source

Supported by

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