This is a document database module made for small-scale applications. Please don't use this module if your data is very important. It is not tested very extensively.
This project is on pypi and on github.
The project is up on pypi (PYthon Package Index). So installing can be done using pip
.
Unix & Mac os X:
pip3 install picodoc
Windows:
pip install picodoc
The objects are not really dicts and lists. So they do not support all functions of those objects.
List supports:
- append
- remove
- iterating over values
- item assignment using index
-
del list[idx]
-
value = list[idx]
-
list[idx] = new_value
-
Dict supports:
- iterating over keys
- item assignment using key
-
del list[key]
-
value = list[key]
-
list[key] = new_value
-
Using the library should be very straight forward. Open a database with the picodoc.open_db
function and use it as if it were a dict.
To get started import the module
import picodoc
Then open the database. (The extension doesn't really matter, but I would suggest using something lile '.db' or '.picodoc')
db = picodoc.open_db('database.picodoc')
Now just treat the db as af it were a basic (see notice) dictionary.
db['users'] = {}
db['users']['donkere.v'] = {
'name': 'Donkere Vader',
'descprition': 'Cool dude π',
}
There are two ways of printing a document.
Either print it as a dict:
print(db['users']['donkere.v'])
>>>
<Document donkere.v>
{
'name': 'Donkere Vader',
'descprition': 'Cool dude π',
}
Or print it as an object:
# this will print it as if it were a document
# <Document {document key}>
print(db['users']['donkere.v'].object_repr())
>>>
<Document donkere.v>
Use the rich module for beautiful output in the console.
Testing is done via the runtests
file.
To run all the tests simply do:
python3 runtests
(If you are on windows use python
in stead of python3
)