How to Hack Together Your Own Database Client in Python

Roshan R Chandar (~Roshan-R)




Tired of pre-built solutions? In this session, we'll dive deep and craft our own MongoDB driver in Python, brick by brick.

Let’s build a simple MongoDB database driver using Python from the ground up. We'll start by peeking under the hood of popular libraries like PyMongo and Motor, deconstructing their secrets to understand how they work.

But the real magic lies in the MongoDB wire protocol, the unsung hero of client-server communication. We'll demystify this protocol, showing you how to build powerful payloads that the server can understand.

Get ready to peel back the layers and explore the OP_MSG operation in detail. We'll use hands-on Python code examples to unveil its potential, empowering you to perform queries, updates, and more with ease.

  1. What is a Database Client? [3 minutes]

    • Definition and purpose of a database client.
    • Examples of operations performed by database clients
  2. Overview of the MongoDB Ecosystem [2 minutes]

    • Introduction to PyMongo and Motor and their analysis
  3. Vision for a New MongoDB Driver [ 3 minutes ] 

    • Objectives
    • Potential advantages
  4. MongoDB Wire Protocol [8 minutes ]

    • Introduction to what wire protocol is
    • Introduction to the OP_MSG command
    • How to manually create and parse OP_MSG payloads

  5. Ctypes [ 3 minutes ]

    • Introduction to the ctypes structure library
    • How to use ctypes to integrate MongoDB's OP_MSG into your Python driver.
  6. Now, What’s Async Code [6 minutes ]

    • Explanation of synchronous vs. asynchronous programming.
    • Introduction to Python's asyncio library.
    • Adapting your MongoDB driver to support asynchronous operations.
  7. Conclusion and Q&A [5 minutes]


Basic python knowledge and a curious mind!

Speaker Info:

Roshan is an enthusiastic Python dev, with a love for exploring the endless possibilities of Python magic! He is a talented presenter with experience at conferences like PyCon Thailand 2023.

He has also achieved success in numerous hackathons and have actively led various Python training sessions. An avid FOSS enthusiast, he has contributed to many open source organisations like the GNOME project and maintains several popular applications.

Currently, Roshan leverages his Python expertise as a backend developer at Strollby, working with Python microservices and GraphQL.

Section: Python in Platform Engineering and Developer Operations
Type: Talk
Target Audience: Beginner
Last Updated: