Norman is a framework for advanced data structures in python using an database-like approach. The range of potential applications is wide, for example in-memory databases, multi-keyed dictionaries or node graphs.
Project description
Norman provides a framework for creating complex data structures using an database-like approach. The range of potential application is wide, for example in-memory databases, multi-keyed dictionaries or node graphs. These applications are illustrated in the following examples.
Database
This is a small database for a personal library:
db = Database() @db.add class Book(Table): name = Field(unique=True) author = Field(index=True) def validate(self): assert isinstance(self.name, str) assert isinstance(self.author, Author) @db.add class Author(Table): surname = Field(unique=True) initials = Field(unique=True, default='') nationality = Field() books = Join(Book.author)
Multi-keyed Dictionary
This table can be used as a dictionary with three keys:
class MultiDict(Table): key1 = Field(unique=True) key2 = Field(unique=True) key3 = Field(unique=True) value = Field()
Values can be added by:
MultiDict(key1=4, key2='abc', key3=0, value='efg')
And queried by:
for m in (MultiDict.key1 == 4 & Multidict.key2 == 'abc'): print(m.value)
Node Graph
This is a graph, where each node can have many parent nodes and many children nodes:
class Link(Table): """ Directional connections between nodes. """ parent = Field(unique=True) child = Field(unique=True) def validate(self): assert isinstance(self.parent, Node) assert isinstance(self.child, Node) class Node(Table): """ Nodes in the graph. """ parents = Join(query=lambda n: (Link.child == n).field('parent')) children = Join(query=lambda n: (Link.parent == n).field('child')) def validate_delete(self): # Delete all connecting links if a node is deleted (Link.parent == self).delete() (Link.child == self).delete()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file norman-0.7.2.zip
.
File metadata
- Download URL: norman-0.7.2.zip
- Upload date:
- Size: 33.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8d27acf63dca2269ce0db48c64248674fba23abaeff14a798cff1ef6f775ec |
|
MD5 | 3eadfe7a410ed65e14fe6366b2876641 |
|
BLAKE2b-256 | 4f332929127bb421a463191f489fd1921cea94f60eff27bd8ad6695839c18d01 |