<commit_before># MongoKit

[MongoDB](http://www.mongodb.org/display/DOCS/Home) is a great schema-less document oriented database. It have a lot of driver for many langages (python, ruby, perl, java, php...).

MongoKit is a python module that brings structured schema and validation layer
on top of the great pymongo driver. It has be written to be as simple and light
as possible with the KISS and DRY principles in mind.

## Philosophy

MongoKit is designed to be:

 * **simple**: MongoKit use plain python type to describe document structure
 * **fast**: MongoKit is fast but if you *really* need to be fast you have access to the raw pymongo layer without changing the API
 * **powerful**: MongoKit brings many feature like document auto-reference, custom types or i18n support.

**Your data is clean:**

> "Tools change, not data". In order to follow this "credo", MongoKit won't
> add any information into your data saved into the database.
> So if you need to use other mongo tools or ODMs in other languages, your
> data won't be polluted by MongoKit's stuff.

## Features

 * schema validation (wich use simple python type for the declaration)
 * schema less feature
 * dot notation
 * nested and complex schema declaration
 * untyped field support
 * required fields validation
 * default values
 * custom validators
 * cross database document reference
 * random query support (which returns a random document from the database)
 * inheritance and polymorphisme support
 * versionized document support (in beta stage)
 * partial auth support (it brings a simple User model) 
 * operator for validation (currently : OR, NOT and IS)
 * simple web framework integration
 * import/export to json
 * i18n support
 * GridFS support
 * document migration support

Go to the full [documentation](http://github.com/namlook/mongokit/wiki)

## A quick example

Document are enhanced python dictionary with a `validate()` method.
A Document declaration look like that:

    >>> from mongokit import *
    >>> import datetime

    >>> connection = Connection()
    
    >>> @connection.register
    ... class BlogPost(Document):
    ...     structure = {
    ...             'title':unicode,
    ...             'body':unicode,
    ...             'author':unicode,
    ...             'date_creation':datetime.datetime,
    ...             'rank':int
    ...     }
    ...     required_fields = ['title','author', 'date_creation']
    ...     default_values = {'rank':0, 'date_creation':datetime.datetime.utcnow}
    ... 

We fire a connection and register our objects.

    >>> blogpost = con.test.example.BlogPost() # this use the db "test" and the collection "example"
    >>> blogpost['title'] = u'my title'
    >>> blogpost['body'] = u'a body'
    >>> blogpost['author'] = u'me'
    >>> blogpost
    {'body': u'a body', 'title': u'my title', 'date_creation': datetime.datetime(...), 'rank': 0, 'author': u'me'}
    >>> blogpost.save()
   
Saving the object will call the `validate()` method.

And you can use more complex structure:

    >>>  @connection.register
    ...  class ComplexDoc(Document):
    ...     __database__ = 'test'
    ...     __collection__ = 'example'
    ...     structure = {
    ...         "foo" : {"content":int},
    ...         "bar" : {
    ...             'bla':{'spam':int}
    ...         }
    ...     }
    ...     required_fields = ['foo.content', 'bar.bla.spam']
     
Please, see the [tutorial](https://github.com/namlook/mongokit/wiki/Tutorial) for more examples.

Suggestion and patches are really welcome. If you find mistakes in the documentation
(english is not my primary langage) feel free to contact me. You can find me (namlook) 
on the freenode #mongodb irc channel or on [twitter](http://twitter.com/namlook)<commit_msg>Add github's syntaxic coloration for python<commit_after># MongoKit

[MongoDB](http://www.mongodb.org/display/DOCS/Home) is a great schema-less document oriented database. It have a lot of driver for many langages (python, ruby, perl, java, php...).

MongoKit is a python module that brings structured schema and validation layer
on top of the great pymongo driver. It has be written to be as simple and light
as possible with the KISS and DRY principles in mind.

## Philosophy

MongoKit is designed to be:

 * **simple**: MongoKit use plain python type to describe document structure
 * **fast**: MongoKit is fast but if you *really* need to be fast you have access to the raw pymongo layer without changing the API
 * **powerful**: MongoKit brings many feature like document auto-reference, custom types or i18n support.

**Your data is clean:**

> "Tools change, not data". In order to follow this "credo", MongoKit won't
> add any information into your data saved into the database.
> So if you need to use other mongo tools or ODMs in other languages, your
> data won't be polluted by MongoKit's stuff.

## Features

 * schema validation (wich use simple python type for the declaration)
 * schema less feature
 * dot notation
 * nested and complex schema declaration
 * untyped field support
 * required fields validation
 * default values
 * custom validators
 * cross database document reference
 * random query support (which returns a random document from the database)
 * inheritance and polymorphisme support
 * versionized document support (in beta stage)
 * partial auth support (it brings a simple User model) 
 * operator for validation (currently : OR, NOT and IS)
 * simple web framework integration
 * import/export to json
 * i18n support
 * GridFS support
 * document migration support

Go to the full [documentation](http://github.com/namlook/mongokit/wiki)

## A quick example

Document are enhanced python dictionary with a `validate()` method.
A Document declaration look like that:

```python
    >>> from mongokit import *
    >>> import datetime

    >>> connection = Connection()
    
    >>> @connection.register
    ... class BlogPost(Document):
    ...     structure = {
    ...             'title':unicode,
    ...             'body':unicode,
    ...             'author':unicode,
    ...             'date_creation':datetime.datetime,
    ...             'rank':int
    ...     }
    ...     required_fields = ['title','author', 'date_creation']
    ...     default_values = {'rank':0, 'date_creation':datetime.datetime.utcnow}
    ... 
```

We fire a connection and register our objects.

```python
    >>> blogpost = con.test.example.BlogPost() # this use the db "test" and the collection "example"
    >>> blogpost['title'] = u'my title'
    >>> blogpost['body'] = u'a body'
    >>> blogpost['author'] = u'me'
    >>> blogpost
    {'body': u'a body', 'title': u'my title', 'date_creation': datetime.datetime(...), 'rank': 0, 'author': u'me'}
    >>> blogpost.save()
```
   
Saving the object will call the `validate()` method.

And you can use more complex structure:

```python
    >>>  @connection.register
    ...  class ComplexDoc(Document):
    ...     __database__ = 'test'
    ...     __collection__ = 'example'
    ...     structure = {
    ...         "foo" : {"content":int},
    ...         "bar" : {
    ...             'bla':{'spam':int}
    ...         }
    ...     }
    ...     required_fields = ['foo.content', 'bar.bla.spam']
```

Please, see the [tutorial](https://github.com/namlook/mongokit/wiki/Tutorial) for more examples.

Suggestion and patches are really welcome. If you find mistakes in the documentation
(english is not my primary langage) feel free to contact me. You can find me (namlook) 
on the freenode #mongodb irc channel or on [twitter](http://twitter.com/namlook)
{'fraction_non_alphanumeric': 0.11654184732623835, 'fraction_numerical': 0.0015766653527788726, 'mean_word_length': 3.0211304807184365, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 77, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3325913', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2039, 'n_words': 831}