SlideShare a Scribd company logo
1 of 55
Round Pegs
       and
   Square Holes
      Django and MongoDB




by Daniel Greenfeld and Audrey Roy
Audrey / Danny

                                                • Principals at Cartwheel
                                                  Web
         Photo credit: Christopher Neugebauer
                                                • Co-founders of
                                                  consumer.io
                                                • Met at PyCon 2010
                                                • Now affianced

@pydanny / @audreyr                                              cartwheelweb.com
What is MongoDB?


       • NoSQL
       • Fast, Scalable, Indexable, Shardable
       • Schema-less

@pydanny / @audreyr                    cartwheelweb.com
What is MongoDB?
          • Written in C++
          • Stores data in BSON (kinda like
            JSON)
          • Uses JavaScript internally for
            scripting
          • Has Python, Ruby, PHP, C, other
            drivers
          • Huge community
@pydanny / @audreyr                    cartwheelweb.com
MongoDB: SQL Analogy



       • Collections are like tables
       • Documents are like records (rows)


@pydanny / @audreyr                   cartwheelweb.com
What is a MongoDB queryset?
                      As served by pymongo




                         Minimalist view

@pydanny / @audreyr                          cartwheelweb.com
What is a MongoDB queryset?
                      As served by pymongo




                A list
           of dictionaries
                         Minimalist view

@pydanny / @audreyr                          cartwheelweb.com
What it looks like
   list                  Minimalist view


   collection = []
   document = {
           '_objectId': ObjectId('4f844e916c97c1000c000003'),
           'username': 'pydanny',
           'fiancee': {
               'username': 'audreyr',
               'location': 'Zurich'
           }
       }
   collection = [document, ]




@pydanny / @audreyr                                 cartwheelweb.com
What it looks like
   list                  Minimalist view

                                     dictiona
   collection = []
   document = {
           '_objectId': ObjectId('4f844e916c97c1000c000003'),
           'username': 'pydanny',
           'fiancee': {
               'username': 'audreyr',
               'location': 'Zurich'
           }
       }
   collection = [document, ]




@pydanny / @audreyr                                 cartwheelweb.com
What it looks like
   list                  Minimalist view

                                     dictiona
   collection = []
   document = {
           '_objectId': ObjectId('4f844e916c97c1000c000003'),
           'username': 'pydanny',
           'fiancee': {
               'username': 'audreyr',
               'location': 'Zurich'
           }
       }
   collection = [document, ]



                      list of dictionaries!
@pydanny / @audreyr                                 cartwheelweb.com
Tools for using
MongoDB with Django
 (actually, most of these are not Django-
“MongoDB connectors”

       • pymongo
       • mongoengine
       • mongokit
       • Django-nonrel
        • the only one here requiring
          Django


@pydanny / @audreyr                     cartwheelweb.com
Option 1
pymongo
pymongo
           http://api.mongodb.org/python/current/
             Official Python binding for MongoDB
    >>> from pymongo import Connection

    >>> connection = Connection()

    >>> my_data = {'rating': 3, 'title': 'I like ice cream'}

    >>> connection.reviews.insert(my_data)

    >>> your_data = {'rating': 3, 'subject': 'You like ice cream'}

    >>> connection.reviews.insert(your_data)




@pydanny / @audreyr                                 cartwheelweb.com
pymongo
           http://api.mongodb.org/python/current/
             Official Python binding for MongoDB
                                     my_data with title
    >>> from pymongo import Connection

    >>> connection = Connection()

    >>> my_data = {'rating': 3, 'title': 'I like ice cream'}

    >>> connection.reviews.insert(my_data)

    >>> your_data = {'rating': 3, 'subject': 'You like ice cream'}

    >>> connection.reviews.insert(your_data)




@pydanny / @audreyr                                 cartwheelweb.com
pymongo
           http://api.mongodb.org/python/current/
             Official Python binding for MongoDB
                                     my_data with title
    >>> from pymongo import Connection

    >>> connection = Connection()

    >>> my_data = {'rating': 3, 'title': 'I like ice cream'}

    >>> connection.reviews.insert(my_data)

    >>> your_data = {'rating': 3, 'subject': 'You like ice cream'}

    >>> connection.reviews.insert(your_data)



                            your_data with subject
@pydanny / @audreyr                                 cartwheelweb.com
pymongo
         [
               {'rating': 3,'title': 'I like ice cream'},
               {'rating': 3, 'subject': 'You like ice cream'}
         ]



         >>>   connection = pymongo.Connection()
         >>>   db = connection.db
         >>>   for review in db.reviews.find({'rating': 3}):
         ...       review['title']
         >>>   for review in db.reviews.find(
         ...          {"title": {"$regex": "ice cream"} }
         ...          ):
         ...       review['title']




@pydanny / @audreyr                                    cartwheelweb.com
pymongo
         [
               {'rating': 3,'title': 'I like ice cream'},
               {'rating': 3, 'subject': 'You like ice cream'}
         ]



         >>>   connection = pymongo.Connection()
         >>>   db = connection.db
         >>>   for review in db.reviews.find({'rating': 3}):
         ...       review['title']
         >>>   for review in db.reviews.find(
         ...          {"title": {"$regex": "ice cream"} }
         ...          ):
         ...       review['title']


                                          Finds all reviews
                                          with a rating of 3
@pydanny / @audreyr                                    cartwheelweb.com
pymongo
         [
               {'rating': 3,'title': 'I like ice cream'},
               {'rating': 3, 'subject': 'You like ice cream'}
         ]



         >>>   connection = pymongo.Connection()
         >>>   db = connection.db
         >>>   for review in db.reviews.find({'rating': 3}):
         ...       review['title']
         >>>   for review in db.reviews.find(
         ...          {"title": {"$regex": "ice cream"} }
         ...          ):
         ...       review['title']




@pydanny / @audreyr                                    cartwheelweb.com
pymongo
         [
               {'rating': 3,'title': 'I like ice cream'},
               {'rating': 3, 'subject': 'You like ice cream'}
         ]



         >>>   connection = pymongo.Connection()
         >>>   db = connection.db
         >>>   for review in db.reviews.find({'rating': 3}):
         ...       review['title']
         >>>   for review in db.reviews.find(
         ...          {"title": {"$regex": "ice cream"} }
         ...          ):
         ...       review['title']


                                   Only finds the document
                                       with ‘title’ in it.
@pydanny / @audreyr                                    cartwheelweb.com
pymongo
                        Pros


       • Really fast, bare metal
       • Lets you go schema-crazy
       • Supported directly by 10gen
        • They say “PyMongo to work with
           recommended way
                               is the
              MongoDB from Python.”


@pydanny / @audreyr                   cartwheelweb.com
pymongo
                        Cons


       • “PyMongo introspection” is an
         oxymoron
       • Very low-level
       • Lose out on ModelForms, Auth,
         Admin, etc
       • Syntax mapperclean as with an
         object
                not as



@pydanny / @audreyr                 cartwheelweb.com
Option 2
MongoEngine
MongoEngine
                      http://mongoengine.org/


                                     Doesn’t this look
import mongoengine as me
                                      like the Django
class Review(me.Document):
                                            ORM?
    title = me.StringField()
    body = me.StringField()
    author = me.StringField()
    created = me.DateTimeField(default=datetime.utcnow)
    rating = me.IntField()




@pydanny / @audreyr                                 cartwheelweb.com
MongoEngine

                                Doesn’t this look
                                 like a Django
                                     query?
          >>> from reviews.models import Review
          >>> for review in Review.objects.all():
          ...     review.title




@pydanny / @audreyr                         cartwheelweb.com
MongoEngine
                      Pros


    • Looks similar to Django ORM code
    • You can develop SUPER-QUICKLY
    • Can use with django-mongonaut for
      introspection
    • Light schema, unenforced by the db
    • Supports some inter-document
      connections

@pydanny / @audreyr                 cartwheelweb.com
MongoEngine
                      Cons

       • Some feel there’s too much structure
       • Validation messages sometimes
         unclear
       • Using it with Django,introspection*on
         the Django Admin’s
                               you lose out
           and ModelForms


        * django-mongonaut addresses this.

@pydanny / @audreyr                   cartwheelweb.com
mongoengine and
         django-mongonaut
                      http://bit.ly/django-mongonaut




@pydanny / @audreyr                          cartwheelweb.com
Option 3
MongoKit
MongoKit
              http://namlook.github.com/mongokit/

       from mongokit import Document, Connection

       connection = Connection()

       @connection.register
       class Review(Document):
           structure = {
                   'title':unicode,
                   'body':unicode,
                   'author':unicode,
                   'created':datetime.datetime,
                   'rating':int
           }
           required_fields = ['title', 'author', 'created']
           default_values = {'rating': 0,
                         'created': datetime.utcnow}


@pydanny / @audreyr                                 cartwheelweb.com
MongoKit
              http://namlook.github.com/mongokit/

       from mongokit import Document, Connection

       connection = Connection()

       @connection.register
       class Review(Document):                 Review model
           structure = {                        representing
                   'title':unicode,               MongoDB
                   'body':unicode,
                   'author':unicode,
                                                  collection
                   'created':datetime.datetime,
                   'rating':int
           }
           required_fields = ['title', 'author', 'created']
           default_values = {'rating': 0,
                         'created': datetime.utcnow}


@pydanny / @audreyr                                cartwheelweb.com
MongoKit
              http://namlook.github.com/mongokit/

       from mongokit import Document, Connection

       connection = Connection()

     @connection.register
     class Review(Document):                 Review model
         structure = {                        representing
                 'title':unicode,               MongoDB
                 'body':unicode,
Expected         'author':unicode,
                                                collection
  fields          'created':datetime.datetime,
                 'rating':int
         }
         required_fields = ['title', 'author', 'created']
         default_values = {'rating': 0,
                       'created': datetime.utcnow}


@pydanny / @audreyr                                cartwheelweb.com
MongoKit
              http://namlook.github.com/mongokit/
                                                   Connect
                                                      to
       from mongokit import Document, Connection   reviews
                                                   collectio
       connection = Connection()
                                                       n
     @connection.register
     class Review(Document):                 Review model
         structure = {                        representing
                 'title':unicode,               MongoDB
                 'body':unicode,
Expected         'author':unicode,
                                                collection
  fields          'created':datetime.datetime,
                 'rating':int
         }
         required_fields = ['title', 'author', 'created']
         default_values = {'rating': 0,
                       'created': datetime.utcnow}


@pydanny / @audreyr                                 cartwheelweb.com
MongoKit
              http://namlook.github.com/mongokit/



     >>> from mongokit import Connection
     >>> connection = Connection()
     >>> for review in connection.Review.find({'rating': 3}):
     ...     review['title']




                      Identical to pymongo queries


@pydanny / @audreyr                                 cartwheelweb.com
MongoKit
                        Pros


       • Light schema, unenforced by the db
        • Or can go all out schemaless!
       • Speed
       • Types are a mix of Python &
         MongoDB
       • Uses pymongo-style queries
@pydanny / @audreyr                  cartwheelweb.com
MongoKit
                        Cons



       • Using itDjango Admin’s lose out
         on the
                  with Django, you
           introspection, ModelForms, auth,
           etc
       • Introspection is hard

@pydanny / @audreyr                    cartwheelweb.com
Option 4
 Django-nonrel
       +
mongodb-engine
Django-nonrel
         + mongodb-engine
                  http://docs.django-nonrel.org

       • A patch to Django thatORM NoSQL
         support to the Django
                               adds

       • Works with GAE, MongoDB, even SQL
         DBs




@pydanny / @audreyr                               cartwheelweb.com
Django-nonrel
         + mongodb-engine
                      Pros

       • Can use Django as you normally
         would
       • Mirrors the ORM functionality
       • Introspection via djangotoolbox

@pydanny / @audreyr                  cartwheelweb.com
Django-nonrel
         + mongodb-engine
                          Cons

       • Fork of the whole Django project.
       • Dependent Django core (still on
         parity with
                     on others to maintain
           Django 1.3).
       • Multi-db usage is confusing

@pydanny / @audreyr                    cartwheelweb.com
Summary


   • pymongo is low-level and well-supported
     by 10gen.
   • MongoEngine is like schemaless Django
     models.
   • MongoKit is like pymongo with extra
     structure.
   • Django-nonrel is a fork of Django 1.3.
@pydanny / @audreyr                cartwheelweb.com
The Take Away?
Danny’s Thoughts
            Can we build a “simple” bridge?

What about a single third-party app that lets you
 combine critical Django apps and MongoDB?

              • django.contrib.auth
              • django.forms
              • django-social-auth /
              registration
              • others...
@pydanny / @audreyr                     cartwheelweb.com
Danny’s Thoughts
  I wonder, why add schemas to schema-less
                           when:
              Relational Databases
              South
              High level Caching
              tools*
        allow you to develop fast moving
     datastores with transactions and built-
               in Djangoorsupport?
                   * cache-machine johnny-cache



@pydanny / @audreyr                   cartwheelweb.com
Danny’s Thoughts

                 Introspection Tool Idea

        Treat introspection like MongoDB
        Queries


             Immediate introspection tool
            (no ‘title’ then don’t show title)

@pydanny / @audreyr                        cartwheelweb.com
Audrey’s Thoughts


        • Schemaless dbs promise
          performance advantages
         • Especially for distributed systems
         • Tradeoff: ACID compliance
http://stackoverflow.com/questions/3856222/whats-the-attraction-of-schemaless-
                               database-systems

 @pydanny / @audreyr                                       cartwheelweb.com
Audrey’s Thoughts
                 “Schemaless database”
                          ==
              ACID-noncompliant database


OK when performance is more important than
    being consistent 100% of the time.



@pydanny / @audreyr                   cartwheelweb.com
Audrey’s Thoughts
               Schemaless Python models
                          !=
            Schemaless MongoDB collections


I think MongoEngine is best unless your use case
           calls for schema anarchy.



 @pydanny / @audreyr                   cartwheelweb.com
Going Forward
Using Django With
              MongoDB

  • Big hurdles: ORM, Admin, ModelForms,
    Auth
   • Were built for relational data
  • But the situation is improving rapidly

@pydanny / @audreyr                 cartwheelweb.com
What needs to be
                 done
  • New introspection tools (working on it)
  • django.forms bridge.
  • django.contrib.admin bridge.
  • Drop-in 1.5?)
    (Django
            replacement for Django Auth

  • Creation of best practices document for
    use of MongoDB with Django.

@pydanny / @audreyr                 cartwheelweb.com
Django Mongonaut

     • Introspection tool for MongoEngine
     • Works well so far
     • Integrate graphing tools
     • Make independent from mongoengine
     • Contributors wanted:
      • https://github.com/pydanny/django-
         mongonaut

@pydanny / @audreyr               cartwheelweb.com
Django Mongonaut
                         Based off of immediate
                           introspection - not
                                definition




@pydanny / @audreyr
                      Mockup        cartwheelweb.com
Django Mongonaut
                         Based off of immediate
                           introspection - not
                                definition
                                   SVG w/links
                                  for examining
                                       nested
                                    structures




@pydanny / @audreyr
                      Mockup        cartwheelweb.com
Final Summary


                             {
                                 pymongo
                                 mongoengine
             Python/             mongokit
             MongoDB tools       django-nonrel
             to consider         django-mongodb
                                 django-
                                 mongonaut




@pydanny / @audreyr                          cartwheelweb.com

More Related Content

What's hot

JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightDonny Wals
 
Distributed Identities with OpenID
Distributed Identities with OpenIDDistributed Identities with OpenID
Distributed Identities with OpenIDBastian Hofmann
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法Tomohiro Nishimura
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
Alfresco tech talk live public api episode 64
Alfresco tech talk live public api episode 64Alfresco tech talk live public api episode 64
Alfresco tech talk live public api episode 64Alfresco Software
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
Every Click Counts (But All the Money Goes to Me)
Every Click Counts (But All the Money Goes to Me)Every Click Counts (But All the Money Goes to Me)
Every Click Counts (But All the Money Goes to Me)Avast
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Schema design
Schema designSchema design
Schema designchristkv
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with DjangoSimon Willison
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 

What's hot (20)

JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than Twilight
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Distributed Identities with OpenID
Distributed Identities with OpenIDDistributed Identities with OpenID
Distributed Identities with OpenID
 
Jquery
JqueryJquery
Jquery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Alfresco tech talk live public api episode 64
Alfresco tech talk live public api episode 64Alfresco tech talk live public api episode 64
Alfresco tech talk live public api episode 64
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Every Click Counts (But All the Money Goes to Me)
Every Click Counts (But All the Money Goes to Me)Every Click Counts (But All the Money Goes to Me)
Every Click Counts (But All the Money Goes to Me)
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Schema design
Schema designSchema design
Schema design
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 

Viewers also liked

Word Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoWord Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoGrant Paton-Simpson
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data VisualizationsDaniel Greenfeld
 
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynoteDaniel Greenfeld
 
Lighting talk on django-social-auth
Lighting talk on django-social-authLighting talk on django-social-auth
Lighting talk on django-social-authDaniel Greenfeld
 
An Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of PythonAn Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of PythonDaniel Greenfeld
 
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsPython Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsP3 InfoTech Solutions Pvt. Ltd.
 
Introduction to py2neo
Introduction to py2neoIntroduction to py2neo
Introduction to py2neoNigel Small
 
Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with PythonGrant Paton-Simpson
 
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web DevelopmentPython Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web DevelopmentP3 InfoTech Solutions Pvt. Ltd.
 
Natural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyNatural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyCharlie Greenbacker
 
How to Write a Popular Python Library by Accident
How to Write a Popular Python Library by AccidentHow to Write a Popular Python Library by Accident
How to Write a Popular Python Library by AccidentDaniel Greenfeld
 
Thinking hard about_python
Thinking hard about_pythonThinking hard about_python
Thinking hard about_pythonDaniel Greenfeld
 
A quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesA quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesNicholas Crouch
 
10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-pythonDaniel Greenfeld
 
Django and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assDjango and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assTobias Lindaaker
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and PythonAndrii Soldatenko
 
From NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceFrom NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceDaniel Greenfeld
 

Viewers also liked (20)

Word Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neoWord Puzzles with Neo4j and Py2neo
Word Puzzles with Neo4j and Py2neo
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data Visualizations
 
The One Way
The One WayThe One Way
The One Way
 
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 Keynote
 
Intro
IntroIntro
Intro
 
Lighting talk on django-social-auth
Lighting talk on django-social-authLighting talk on django-social-auth
Lighting talk on django-social-auth
 
An Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of PythonAn Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of Python
 
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsPython Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List Comprehensions
 
Introduction to py2neo
Introduction to py2neoIntroduction to py2neo
Introduction to py2neo
 
Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with Python
 
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web DevelopmentPython Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
 
Natural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in LumifyNatural Language Processing and Graph Databases in Lumify
Natural Language Processing and Graph Databases in Lumify
 
How to Write a Popular Python Library by Accident
How to Write a Popular Python Library by AccidentHow to Write a Popular Python Library by Accident
How to Write a Popular Python Library by Accident
 
Thinking hard about_python
Thinking hard about_pythonThinking hard about_python
Thinking hard about_python
 
A quick review of Python and Graph Databases
A quick review of Python and Graph DatabasesA quick review of Python and Graph Databases
A quick review of Python and Graph Databases
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python
 
Django and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks assDjango and Neo4j - Domain modeling that kicks ass
Django and Neo4j - Domain modeling that kicks ass
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and Python
 
From NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceFrom NASA to Startups to Big Commerce
From NASA to Startups to Big Commerce
 

Similar to Round pegs and square holes

Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedMongoDB
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011Steven Francia
 
Django class based views (Dutch Django meeting presentation)
Django class based views (Dutch Django meeting presentation)Django class based views (Dutch Django meeting presentation)
Django class based views (Dutch Django meeting presentation)Reinout van Rees
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Scrapy talk at DataPhilly
Scrapy talk at DataPhillyScrapy talk at DataPhilly
Scrapy talk at DataPhillyobdit
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...Prasoon Kumar
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1MicroPyramid .
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 

Similar to Round pegs and square holes (20)

Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Django
DjangoDjango
Django
 
Webinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting StartedWebinar: Build an Application Series - Session 2 - Getting Started
Webinar: Build an Application Series - Session 2 - Getting Started
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 
Django class based views (Dutch Django meeting presentation)
Django class based views (Dutch Django meeting presentation)Django class based views (Dutch Django meeting presentation)
Django class based views (Dutch Django meeting presentation)
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Scrapy talk at DataPhilly
Scrapy talk at DataPhillyScrapy talk at DataPhilly
Scrapy talk at DataPhilly
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 

More from Daniel Greenfeld

More from Daniel Greenfeld (13)

Future of Collaboration
Future of CollaborationFuture of Collaboration
Future of Collaboration
 
Advanced Django Forms Usage
Advanced Django Forms UsageAdvanced Django Forms Usage
Advanced Django Forms Usage
 
Confessions of Joe Developer
Confessions of Joe DeveloperConfessions of Joe Developer
Confessions of Joe Developer
 
Python Worst Practices
Python Worst PracticesPython Worst Practices
Python Worst Practices
 
Django Worst Practices
Django Worst PracticesDjango Worst Practices
Django Worst Practices
 
How to sell django panel
How to sell django panelHow to sell django panel
How to sell django panel
 
Pinax Long Tutorial Slides
Pinax Long Tutorial SlidesPinax Long Tutorial Slides
Pinax Long Tutorial Slides
 
Testing In Django
Testing In DjangoTesting In Django
Testing In Django
 
Django Uni-Form
Django Uni-FormDjango Uni-Form
Django Uni-Form
 
Nova Django
Nova DjangoNova Django
Nova Django
 
Pinax Introduction
Pinax IntroductionPinax Introduction
Pinax Introduction
 
Why Django
Why DjangoWhy Django
Why Django
 
Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Round pegs and square holes

  • 1. Round Pegs and Square Holes Django and MongoDB by Daniel Greenfeld and Audrey Roy
  • 2. Audrey / Danny • Principals at Cartwheel Web Photo credit: Christopher Neugebauer • Co-founders of consumer.io • Met at PyCon 2010 • Now affianced @pydanny / @audreyr cartwheelweb.com
  • 3. What is MongoDB? • NoSQL • Fast, Scalable, Indexable, Shardable • Schema-less @pydanny / @audreyr cartwheelweb.com
  • 4. What is MongoDB? • Written in C++ • Stores data in BSON (kinda like JSON) • Uses JavaScript internally for scripting • Has Python, Ruby, PHP, C, other drivers • Huge community @pydanny / @audreyr cartwheelweb.com
  • 5. MongoDB: SQL Analogy • Collections are like tables • Documents are like records (rows) @pydanny / @audreyr cartwheelweb.com
  • 6. What is a MongoDB queryset? As served by pymongo Minimalist view @pydanny / @audreyr cartwheelweb.com
  • 7. What is a MongoDB queryset? As served by pymongo A list of dictionaries Minimalist view @pydanny / @audreyr cartwheelweb.com
  • 8. What it looks like list Minimalist view collection = [] document = { '_objectId': ObjectId('4f844e916c97c1000c000003'), 'username': 'pydanny', 'fiancee': { 'username': 'audreyr', 'location': 'Zurich' } } collection = [document, ] @pydanny / @audreyr cartwheelweb.com
  • 9. What it looks like list Minimalist view dictiona collection = [] document = { '_objectId': ObjectId('4f844e916c97c1000c000003'), 'username': 'pydanny', 'fiancee': { 'username': 'audreyr', 'location': 'Zurich' } } collection = [document, ] @pydanny / @audreyr cartwheelweb.com
  • 10. What it looks like list Minimalist view dictiona collection = [] document = { '_objectId': ObjectId('4f844e916c97c1000c000003'), 'username': 'pydanny', 'fiancee': { 'username': 'audreyr', 'location': 'Zurich' } } collection = [document, ] list of dictionaries! @pydanny / @audreyr cartwheelweb.com
  • 11. Tools for using MongoDB with Django (actually, most of these are not Django-
  • 12. “MongoDB connectors” • pymongo • mongoengine • mongokit • Django-nonrel • the only one here requiring Django @pydanny / @audreyr cartwheelweb.com
  • 14. pymongo http://api.mongodb.org/python/current/ Official Python binding for MongoDB >>> from pymongo import Connection >>> connection = Connection() >>> my_data = {'rating': 3, 'title': 'I like ice cream'} >>> connection.reviews.insert(my_data) >>> your_data = {'rating': 3, 'subject': 'You like ice cream'} >>> connection.reviews.insert(your_data) @pydanny / @audreyr cartwheelweb.com
  • 15. pymongo http://api.mongodb.org/python/current/ Official Python binding for MongoDB my_data with title >>> from pymongo import Connection >>> connection = Connection() >>> my_data = {'rating': 3, 'title': 'I like ice cream'} >>> connection.reviews.insert(my_data) >>> your_data = {'rating': 3, 'subject': 'You like ice cream'} >>> connection.reviews.insert(your_data) @pydanny / @audreyr cartwheelweb.com
  • 16. pymongo http://api.mongodb.org/python/current/ Official Python binding for MongoDB my_data with title >>> from pymongo import Connection >>> connection = Connection() >>> my_data = {'rating': 3, 'title': 'I like ice cream'} >>> connection.reviews.insert(my_data) >>> your_data = {'rating': 3, 'subject': 'You like ice cream'} >>> connection.reviews.insert(your_data) your_data with subject @pydanny / @audreyr cartwheelweb.com
  • 17. pymongo [ {'rating': 3,'title': 'I like ice cream'}, {'rating': 3, 'subject': 'You like ice cream'} ] >>> connection = pymongo.Connection() >>> db = connection.db >>> for review in db.reviews.find({'rating': 3}): ... review['title'] >>> for review in db.reviews.find( ... {"title": {"$regex": "ice cream"} } ... ): ... review['title'] @pydanny / @audreyr cartwheelweb.com
  • 18. pymongo [ {'rating': 3,'title': 'I like ice cream'}, {'rating': 3, 'subject': 'You like ice cream'} ] >>> connection = pymongo.Connection() >>> db = connection.db >>> for review in db.reviews.find({'rating': 3}): ... review['title'] >>> for review in db.reviews.find( ... {"title": {"$regex": "ice cream"} } ... ): ... review['title'] Finds all reviews with a rating of 3 @pydanny / @audreyr cartwheelweb.com
  • 19. pymongo [ {'rating': 3,'title': 'I like ice cream'}, {'rating': 3, 'subject': 'You like ice cream'} ] >>> connection = pymongo.Connection() >>> db = connection.db >>> for review in db.reviews.find({'rating': 3}): ... review['title'] >>> for review in db.reviews.find( ... {"title": {"$regex": "ice cream"} } ... ): ... review['title'] @pydanny / @audreyr cartwheelweb.com
  • 20. pymongo [ {'rating': 3,'title': 'I like ice cream'}, {'rating': 3, 'subject': 'You like ice cream'} ] >>> connection = pymongo.Connection() >>> db = connection.db >>> for review in db.reviews.find({'rating': 3}): ... review['title'] >>> for review in db.reviews.find( ... {"title": {"$regex": "ice cream"} } ... ): ... review['title'] Only finds the document with ‘title’ in it. @pydanny / @audreyr cartwheelweb.com
  • 21. pymongo Pros • Really fast, bare metal • Lets you go schema-crazy • Supported directly by 10gen • They say “PyMongo to work with recommended way is the MongoDB from Python.” @pydanny / @audreyr cartwheelweb.com
  • 22. pymongo Cons • “PyMongo introspection” is an oxymoron • Very low-level • Lose out on ModelForms, Auth, Admin, etc • Syntax mapperclean as with an object not as @pydanny / @audreyr cartwheelweb.com
  • 24. MongoEngine http://mongoengine.org/ Doesn’t this look import mongoengine as me like the Django class Review(me.Document): ORM? title = me.StringField() body = me.StringField() author = me.StringField() created = me.DateTimeField(default=datetime.utcnow) rating = me.IntField() @pydanny / @audreyr cartwheelweb.com
  • 25. MongoEngine Doesn’t this look like a Django query? >>> from reviews.models import Review >>> for review in Review.objects.all(): ... review.title @pydanny / @audreyr cartwheelweb.com
  • 26. MongoEngine Pros • Looks similar to Django ORM code • You can develop SUPER-QUICKLY • Can use with django-mongonaut for introspection • Light schema, unenforced by the db • Supports some inter-document connections @pydanny / @audreyr cartwheelweb.com
  • 27. MongoEngine Cons • Some feel there’s too much structure • Validation messages sometimes unclear • Using it with Django,introspection*on the Django Admin’s you lose out and ModelForms * django-mongonaut addresses this. @pydanny / @audreyr cartwheelweb.com
  • 28. mongoengine and django-mongonaut http://bit.ly/django-mongonaut @pydanny / @audreyr cartwheelweb.com
  • 30. MongoKit http://namlook.github.com/mongokit/ from mongokit import Document, Connection connection = Connection() @connection.register class Review(Document): structure = { 'title':unicode, 'body':unicode, 'author':unicode, 'created':datetime.datetime, 'rating':int } required_fields = ['title', 'author', 'created'] default_values = {'rating': 0, 'created': datetime.utcnow} @pydanny / @audreyr cartwheelweb.com
  • 31. MongoKit http://namlook.github.com/mongokit/ from mongokit import Document, Connection connection = Connection() @connection.register class Review(Document): Review model structure = { representing 'title':unicode, MongoDB 'body':unicode, 'author':unicode, collection 'created':datetime.datetime, 'rating':int } required_fields = ['title', 'author', 'created'] default_values = {'rating': 0, 'created': datetime.utcnow} @pydanny / @audreyr cartwheelweb.com
  • 32. MongoKit http://namlook.github.com/mongokit/ from mongokit import Document, Connection connection = Connection() @connection.register class Review(Document): Review model structure = { representing 'title':unicode, MongoDB 'body':unicode, Expected 'author':unicode, collection fields 'created':datetime.datetime, 'rating':int } required_fields = ['title', 'author', 'created'] default_values = {'rating': 0, 'created': datetime.utcnow} @pydanny / @audreyr cartwheelweb.com
  • 33. MongoKit http://namlook.github.com/mongokit/ Connect to from mongokit import Document, Connection reviews collectio connection = Connection() n @connection.register class Review(Document): Review model structure = { representing 'title':unicode, MongoDB 'body':unicode, Expected 'author':unicode, collection fields 'created':datetime.datetime, 'rating':int } required_fields = ['title', 'author', 'created'] default_values = {'rating': 0, 'created': datetime.utcnow} @pydanny / @audreyr cartwheelweb.com
  • 34. MongoKit http://namlook.github.com/mongokit/ >>> from mongokit import Connection >>> connection = Connection() >>> for review in connection.Review.find({'rating': 3}): ... review['title'] Identical to pymongo queries @pydanny / @audreyr cartwheelweb.com
  • 35. MongoKit Pros • Light schema, unenforced by the db • Or can go all out schemaless! • Speed • Types are a mix of Python & MongoDB • Uses pymongo-style queries @pydanny / @audreyr cartwheelweb.com
  • 36. MongoKit Cons • Using itDjango Admin’s lose out on the with Django, you introspection, ModelForms, auth, etc • Introspection is hard @pydanny / @audreyr cartwheelweb.com
  • 37. Option 4 Django-nonrel + mongodb-engine
  • 38. Django-nonrel + mongodb-engine http://docs.django-nonrel.org • A patch to Django thatORM NoSQL support to the Django adds • Works with GAE, MongoDB, even SQL DBs @pydanny / @audreyr cartwheelweb.com
  • 39. Django-nonrel + mongodb-engine Pros • Can use Django as you normally would • Mirrors the ORM functionality • Introspection via djangotoolbox @pydanny / @audreyr cartwheelweb.com
  • 40. Django-nonrel + mongodb-engine Cons • Fork of the whole Django project. • Dependent Django core (still on parity with on others to maintain Django 1.3). • Multi-db usage is confusing @pydanny / @audreyr cartwheelweb.com
  • 41. Summary • pymongo is low-level and well-supported by 10gen. • MongoEngine is like schemaless Django models. • MongoKit is like pymongo with extra structure. • Django-nonrel is a fork of Django 1.3. @pydanny / @audreyr cartwheelweb.com
  • 43. Danny’s Thoughts Can we build a “simple” bridge? What about a single third-party app that lets you combine critical Django apps and MongoDB? • django.contrib.auth • django.forms • django-social-auth / registration • others... @pydanny / @audreyr cartwheelweb.com
  • 44. Danny’s Thoughts I wonder, why add schemas to schema-less when: Relational Databases South High level Caching tools* allow you to develop fast moving datastores with transactions and built- in Djangoorsupport? * cache-machine johnny-cache @pydanny / @audreyr cartwheelweb.com
  • 45. Danny’s Thoughts Introspection Tool Idea Treat introspection like MongoDB Queries Immediate introspection tool (no ‘title’ then don’t show title) @pydanny / @audreyr cartwheelweb.com
  • 46. Audrey’s Thoughts • Schemaless dbs promise performance advantages • Especially for distributed systems • Tradeoff: ACID compliance http://stackoverflow.com/questions/3856222/whats-the-attraction-of-schemaless- database-systems @pydanny / @audreyr cartwheelweb.com
  • 47. Audrey’s Thoughts “Schemaless database” == ACID-noncompliant database OK when performance is more important than being consistent 100% of the time. @pydanny / @audreyr cartwheelweb.com
  • 48. Audrey’s Thoughts Schemaless Python models != Schemaless MongoDB collections I think MongoEngine is best unless your use case calls for schema anarchy. @pydanny / @audreyr cartwheelweb.com
  • 50. Using Django With MongoDB • Big hurdles: ORM, Admin, ModelForms, Auth • Were built for relational data • But the situation is improving rapidly @pydanny / @audreyr cartwheelweb.com
  • 51. What needs to be done • New introspection tools (working on it) • django.forms bridge. • django.contrib.admin bridge. • Drop-in 1.5?) (Django replacement for Django Auth • Creation of best practices document for use of MongoDB with Django. @pydanny / @audreyr cartwheelweb.com
  • 52. Django Mongonaut • Introspection tool for MongoEngine • Works well so far • Integrate graphing tools • Make independent from mongoengine • Contributors wanted: • https://github.com/pydanny/django- mongonaut @pydanny / @audreyr cartwheelweb.com
  • 53. Django Mongonaut Based off of immediate introspection - not definition @pydanny / @audreyr Mockup cartwheelweb.com
  • 54. Django Mongonaut Based off of immediate introspection - not definition SVG w/links for examining nested structures @pydanny / @audreyr Mockup cartwheelweb.com
  • 55. Final Summary { pymongo mongoengine Python/ mongokit MongoDB tools django-nonrel to consider django-mongodb django- mongonaut @pydanny / @audreyr cartwheelweb.com

Editor's Notes

  1. A: We have a specific time we have to present in, so please hold your questions and comments to the end.\n
  2. A, D, A\n
  3. D\n
  4. D\n
  5. A\n
  6. D\n
  7. D\n
  8. D\n
  9. A: Which is why we’re presenting here today rather than at LA Django - this is useful info for any Python developer.\n
  10. A\n
  11. D - Using a review system...\n
  12. D\n
  13. D\n
  14. D: MongoDB queries are meant for schema-less data.\n
  15. D: MongoDB queries are meant for schema-less data.\n
  16. D: You can do crazy things like have every document in a collection have a completely different schema. \n
  17. D: No introspection tools, just the shell. Certainly no admin. \n
  18. A\n
  19. A\n
  20. A\n
  21. A\n
  22. A: If you use ReferenceFields all the time, you might as well be using SQL\n
  23. A\n
  24. D\n
  25. D\n
  26. D\n
  27. D\n
  28. D\n
  29. D\n
  30. D\n
  31. A\n
  32. A\n
  33. A\n
  34. A: According to posts on the mailing list, you should be able to use multiple databases. But I pored over the docs/mailing list and couldn’t find an example of, say, using Postgres for auth and MongoDB for a custom app\n
  35. D, A, D, A\n
  36. \n
  37. D I’m in discussion with some other Python/MongoDB aficionados.\n
  38. D I love normalization. I love what you can do with a schema. I love what you can do without a schema\n
  39. D\n
  40. A: Atomicity, consistency, isolation, durability. Properties that guarantee that a db transaction has been processed reliably.\n
  41. A: Atomicity, consistency, isolation, durability. Properties that guarantee that a db transaction has been processed reliably.\nThere’s the very small risk that data you retrieve could be in a temporary inconsistent state.\n
  42. A: NYT, Heroku, Intuit, IGN, Posterous, and others use Ruby’s MongoMapper\nIn the Ruby world, Mongo object mappers are much more prevalent.\n
  43. D\n
  44. D\n
  45. D\n
  46. D\n
  47. D\n
  48. A\n