Skip to main content

A small Document Oriented Databse

Project description


Jardb is a small document oriented database, which is Nosql,easy to use and tiny.

It is suitable for local applications to save data and configurations.

Jardb use no more than Python Standard Library.


Author:Lutong Chen


  1. Fast: 10 millions insert in minutes.
  2. Easy: API is easy to learn and use.
  3. Tiny: One file based database.
  4. Automatic: Auto save from memery to disk.
  5. Logs: Write log into file
  6. Test: More Than 90% unit test coverage.


pip is available new.python 2.7 and 3.3+ is required.

>>> pip install jardb


>>> pip3  install jardb



There are three ways to Storage:Json, Binary File and Memery.

  • “json://”: A json file would be create, all information can be seen.
  • file://”: A binary file created by pickle.dump
  • “memery://”: All data will not be saved as a file and would disappear after jardb quits.

Open a jardb database should be a url-like string start with “json://”,”file://” or “memery://”:

>>> from jardb import jardb
>>> db = jardb("json://database.db")

other parameters:

param autosave:boolean, use autosave or not.
param debug:print logs in the terminal.
param log:A log file path.If defined,logs will be written into it.

Read, Initialize, Save and Close

Create a new database like:

>>> db.create()

Open from a existed file like:


Save to disk:


“Save AS” another file:

>>> db.backup("file_path")

You should understand that if you turn it on, it may cause performance loss(though a little).If you turn it off,you should save your database from time to time, because it will only write datas into file only once before it quits.

Close a database like:

>>> db.close()

jardb.close() will call Also, before jardb exits, jardb will automatical be called.

Create Dbtable and DbConfig

There are two kinds of elements that can be directly inserted into database: DbConfig and DbTable.

  • DbConfig is like a python dictionary or a ‘.plist’,’.ini’ or ‘.conf’ file.
  • DbTable is the common Table in Database.

Create a new DbConfig:

>>> db.create_config(config_name,{'AppName':'jardb','Version':'0.0.3'})
param config_name:
param config_dict:
 a python dictionary.

config_name will not check uniqueness. Please be careful with it.

Create a new Table:

>>> create_table('Users',{}):
param table_name:
 You know what it means.
param table_attr:
 properties for fields in this table.

It is expected as a dictionary.Dictionary Key should be field name,such as ‘Users’,’email’. Dictionary Value should be a list contains its properties, such as [“AutoIncrease”,”Unique”,”NotNull”]

“Unique”:jardb will check the Uniqueness of certain field.
“NotNull”:jardb will check before insert.
“AutoIncrease”:If the field is not be specified,jardb will automatical appoint one.

You don’t have to all fields.You can ignore one if it doesn’t contain such properties.


table_name will not check uniqueness. Please be careful with it.

Remove a DbConfig or DbTable

>>> db.remove('Users')

Query and Operations

You need to get a query object before you operate a DbConfig or DbTable

>>> q1 = db.get_config('Config')
>>> q2 = db.get_table('Users')

Here are some examples:

>>> q1.add({'user':1,'secure':2})   # Insert value
>>> q1.add({'user':5,'data':123})   # Insert and change value
>>> q1.remove('secure')             # Remove
>>> print(q1.has('secure'))         # Has key
>>> print(q1.has('user'))
>>> print(q1.get('secure'))         # Get value
>>> print(q1.get('user'))
>>> print(q1.value())               # Show raw data
{'user': 5, 'data': 123}

Another example:

Get a query object.

>>> q2 = db.get_table('Users')
  • Filter can select records using a python-like language.
  • Remove can delete records.
>>> q2.filter("$id %3 == 0 and is_admin == True").remove()
  • Update can change the value of selected records.
>>> q2.update({'is_admin':False})
  • Find is another way to select records.
  • Sort to sort records by a certain field.
  • Get can get ‘top k’ records.
  • Value is used to show raw data
>>> q2.find({'is_admin':False}).sort('id').get(5).value()
  • Map : Given a field name, and return all values of this field.
>>> print(col.filter("$User_id % 4 == 0").map('id'))

With all those function you can use jardb easily.

You can also use jardb.compose to operate database.More details in source code。


You can write logs into a file like:

>>> db = jardb.jardb('json://database.db',log = 'database.log')

Also let it print in the terminal:

>>> db = jardb.jardb('json://database.db',debug = True)

Notice that if log parameter is specified, log will be find in the file no matter ‘debug’ is True or False.

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
jardb-0.0.5.tar.gz (17.3 kB) Copy SHA256 hash SHA256 Source None Jan 22, 2018

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