A flat file drop in replacement for mongodb. Requires Tinydb
Project description
Purpose
A simple wrapper to make a drop in replacement for mongodb out of tinydb. This module is an attempt to add an interface familiar to those currently using pymongo.
Status
Unit testing is currently being worked on and functionality is being added to the library. Current coverage is 93%. Current builds tested on Python versions 2.7 and 3.3+.
Installation
The latest stable release can be installed via pip install tinymongo.
The library is currently under rapid development and a more recent version may be desired.
In this case, simply clone this repository, navigate to the root project directory, and python setup.py install
or use pip install git+https://github.com/schapman1974/tinymongo.git#egg=tinymongo
This is a pure python distribution and - thus - should require no external compilers or tools besides those contained within Python itself.
Examples
The quick start is shown below. For a more detailed look at tinymongo, take a look at demo.py within the repository.
from tinymongo import TinyMongoClient
# you can include a folder name or absolute path
# as a parameter if not it will default to "tinydb"
connection = TinyMongoClient()
# either creates a new database file or accesses an existing one named `my_tiny_database`
db = connection.my_tiny_database
# either creates a new collection or accesses an existing one named `users`
collection = db.users
# insert data adds a new record returns _id
record_id = collection.insert_one({"username": "admin", "password": "admin", "module":"somemodule"})
user_info = collection.find_one({"_id": record_id}) # returns the record inserted
# you can also use it directly
db.users.insert_one({"username": "admin"})
# returns a list of all users of 'module'
users = db.users.find({'module': 'module'})
#update data returns True if successful and False if unsuccessful
upd = db.users.update_one({"username": "admin"}, {"$set": {"module":"someothermodule"}})
# Sorting users by its username DESC
# omitting `filter` returns all records
db.users.find(sort={'username': -1})
# Pagination of the results
# Getting the first 20 records
db.users.find(sort={'username': -1}, skip=0, limit=20)
# Getting next 20 records
db.users.find(sort={'username': -1}, skip=20, limit=20)
# Getting the total of records
db.users.count()
Flask-Admin
This extension can work with Flask-Admin which gives a web based administrative panel to your TinyDB. Flask-Admin has features like filtering, search, web forms to perform CRUD (Create, Read, Update, Delete) of the TinyDB records.
You can find the example of Flask-Admin with TinyMongo in Flask-Admin Examples Repository
Contributions
Contributions are welcome! Currently, the most valuable contributions would be:
adding test cases
adding functionality consistent with pymongo
documentation
identifying bugs and issues
Future Development
I will also be adding support for gridFS by storing the files somehow and indexing them in a db like mongo currently does
More to come……
License
MIT License
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.