One of the things that's been nice about working with
SourceForgefor the last few months is the chance I get to work with new open source technology and contribute something back. Well, the first (in a long series, I hope) of projects we're putting out there as the result of recent work is a little library we wrote called Ming. It's been available over git for a while, but I just finished publishing our first "official" release, with a tutorial, over at
http://merciless.sourceforge.netand
http://pypi.python.org/pypi/Ming/0.1. Ming gives you a way of enforcing schemas on a MongoDB database in a Python application. We also throw in automatic, lazy schema migration for good measure.
If you haven't heard of it yet,
MongoDBdescribes itself as on its website as follows:
MongoDB (from "humongous") is a scalable, high-performance, open source, schema-free, document-oriented database.
There are lots of trade-offs to consider when using a non-relational database like MongoDB. On the plus side, MongoDB is simple to develop for (no SQL), extremely fast, and models hierarchical relationships really nicely. On the downside, we give up relational integrity constraints and transactional behavior.
With all the flexibility provided by MongoDB, however, comes some danger. When the database is schema-free, you have to spend extra code making sure that the data you put in and the data you take out is valid for your application. That's where Ming comes in. A play off the character of Ming the Merciless who ruled the planet of Mongo with an iron fist in Flash Gordon, the Ming library provides a succinct way to specify the requirements your application has for the data it produces and consumes. Ming also supports lazy migration of documents across schema revisions. To give you a flavor for how easy this can be, here is a sample schema with migration from the tutorial:
from ming.datastore import DataStore
from ming import Session
from ming import Document, Field, schemabind = DataStore('mongo://localhost:27017/tutorial')
session = Session(bind)class OldWikiPage(Document):
class __mongometa__:
session = session
name = 'wiki_page' _id = Field(schema.ObjectId)
title = Field(str)
text = Field(str, if_missing='')
metadata = Field(dict(
tags=[str],
categories=[str]))class WikiPage(Document):
class __mongometa__:
session = session
name = 'wiki_page'
version_of = OldWikiPage
def migrate(data):
result = dict(
data,
tags=data['metadata']['tags'],
categories=data['metadata']['categories'],
version=1)
del result['metadata']
return result _id = Field(schema.ObjectId)
version = Field(1)
title = Field(str)
text = Field(str, if_missing='')
tags = Field([str])
categories = Field([str])
Hopefully, that's enough to whet your appetite for now. Rather than duplicating the entire tutorial, I'll direct you to the docs at http://merciless.sourceforge.net for more information. Let me know what you think!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4