Learn Python with Talk Python's 270 hours of courses

EdgeDB - Building a database in Python

Episode #355, published Sun, Mar 6, 2022, recorded Wed, Feb 16, 2022

What database are you using in your apps these days? If you like most Python people, it's probably PostgreSQL. If you roll with NoSQL like me, you're probably using MongoDB. Maybe you're even using a graph database focused more on relationships.

But there's a new Python database in town, and as you learn in during this episode, many critical Python libraries have come into existence because of it. This database is called EdgeDB. EdgeDB is built upon Postgres, implemented mostly in python, and is something of a marriage of a traditional relational database and an ORM.

Python's async and await keywords, uvloop - the high performance asyncio event loop, and asyncpg all have ties back to the creation of EdgeDB.

Yury Selivanov, the co-founder & CEO of EdgeDB, PSF fellow, and Python core developer is here to tell use about EdgeDB along with the history of many of these impactful language features and packages.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests introduction and background

Yuri Selivanov is the co-founder and CEO of EdgeDB. He is a Python core developer and a major contributor behind many well-known Python technologies, especially in the async and concurrency space. Examples of Yuri’s work include the async and await syntax in Python (PEP 492), UVLoop for faster asyncio event looping, and asyncpg, an advanced asynchronous driver for PostgreSQL. His deep involvement in the Python community and passionate drive to simplify database technology ultimately led to the creation of EdgeDB, which combines aspects of relational and graph databases on top of PostgreSQL.

What to Know If You're New to Python

Here are a few tips and resources to help you better follow the concepts discussed in this episode:

  • Start with basic Python syntax (functions, loops, classes) to understand the examples of concurrency and database code.
  • Familiarize yourself with how Python's async and await keywords let you build scalable applications that handle many connections or tasks at once.
  • Recognize that databases often require specialized libraries in Python (e.g., asyncpg or ORMs). This episode explores how EdgeDB can eliminate some typical complexity.

Key points and takeaways

  1. EdgeDB as a “Next-Gen” Database EdgeDB is a new project built on top of PostgreSQL but offers a higher-level schema and a more intuitive query language, EdgeQL. Rather than forcing developers to think in terms of tables and rows, EdgeDB presents a graph-like model with strong relational underpinnings. This reduces or even removes the need for an ORM while still benefiting from Postgres's reliability and ecosystem.
  2. Built Primarily in Python Much of EdgeDB’s implementation is done in Python (with speed-critical parts in Cython) to leverage the language’s readability and extensive ecosystem. The team uses multi-processing architectures to handle concurrent IO in the core server process. By carefully caching queries and splitting out tasks, EdgeDB remains high performance while staying developer-friendly.
  3. Postgres Under the Hood While EdgeDB is perceived as a new database, under the covers it relies on a specialized Postgres instance. This provides a stable, well-tested foundation and allows EdgeDB to focus on the higher-level features. Developers thus enjoy Postgres-level consistency, reliability, and tooling, with a modern interface layered on top.
  4. Async and Await in Python Yuri Selivanov was instrumental in adding async and await syntax (PEP 492) to Python, significantly simplifying asynchronous code. This design allows Python developers to write high-throughput, low-latency networking code in a style similar to synchronous code. The addition of async context managers (async with) and iteration (async for) enhances code readability and safety.
  5. UVLoop: A High-Performance Event Loop UVLoop is a drop-in replacement for the built-in asyncio event loop that uses libuv (Node.js’s event loop library) under the hood. Installing UVLoop can significantly boost your application’s performance for IO-heavy tasks. You simply import and install it in your Python code to get better concurrency without major refactoring.
  6. asyncpg: PostgreSQL at Top Speed To power EdgeDB’s communication with Postgres, Yuri’s team developed asyncpg, an asynchronous Postgres driver. It’s one of the fastest available drivers across many languages, largely due to its lean architecture, use of binary protocols, and speed-critical portions built in Cython. Even if you’re not using EdgeDB, asyncpg can accelerate your Python + PostgreSQL projects.
  7. EdgeQL vs. SQL In EdgeQL, you navigate relationships in a more natural, nested manner rather than performing multiple JOINs. By design, even deeply nested queries compile to a single SQL statement to reduce round trips and ensure atomicity. Compared to SQL, EdgeQL can drastically improve code clarity, especially for complex, real-world data models.
  8. Caching and Compiling for Performance EdgeDB’s compiler caches queries, reducing overhead for repeated operations. It also automatically detects when only constants change in a query so it doesn’t recompile the entire statement. This technique, combined with Postgres’s own query-planning caches, yields performance close to raw SQL in many scenarios.
  9. Future Enhancements for EdgeDB The conversation covered potential features such as advanced access control, inline Python UDFs (user-defined functions), and extended GraphQL compatibility. The team is actively working on group-by queries in EdgeQL, expanded analytics, and other ways to avoid dropping to raw SQL. This keeps developer velocity high while bridging the gap between a relational database and a “no boilerplate” data interface.
  10. Open Source + Cloud Service EdgeDB is open-sourced under the Apache 2.0 license, ensuring it remains free to use, self-host, and modify. On the business side, the EdgeDB team plans to offer a managed cloud version of EdgeDB—similar to hosting providers for Postgres or MongoDB—so developers can focus on building their apps without managing infrastructure.

Interesting quotes and stories

  • On the impetus for async and await: Yuri shared that he was exploring a better Pythonic way to do asynchronous transactions and realized a dedicated language-level keyword was necessary.
  • Why build on Postgres?: “We knew we needed the reliability and core speed of Postgres,” explained Yuri, “but we wanted a more natural data model for developers.”

Key definitions and terms

  • AsyncIO: Python’s built-in framework for asynchronous programming, allowing single-threaded concurrency by switching tasks whenever one is idle.
  • Cython: A superset of Python that compiles to C for speed gains, especially important for tight loops and data processing.
  • ORM (Object-Relational Mapping): A library or framework that maps between objects in code and relational database tables, often leading to complexity that EdgeDB aims to eliminate.
  • EdgeQL: The high-level query language used by EdgeDB, designed to combine relational rigor with graph-like access patterns.

Learning resources

Overall takeaway

EdgeDB represents a significant rethinking of relational databases, blending the proven backbone of PostgreSQL with a new, Python-friendly query language and schema model. Thanks to powerful Python-based tools such as asyncpg and UVLoop, EdgeDB eliminates many ORM pain points, letting developers focus on data rather than glue code. Coupled with the open-source model and upcoming hosted services, EdgeDB has the potential to reshape the Python database landscape for both small teams and large enterprises alike.

Links from the show

Yury Selivanov: @1st1

MagicPython: github.com/MagicStack/MagicPython
uvloop: github.com/MagicStack/uvloop
asyncpg: github.com/MagicStack/asyncpg
TaskGroups and ExceptionGroups: twitter.com
EdgeDB: edgedb.com
Schema modeling: edgedb.com/showcase/data-modeling
Easy EdgeDB book: edgedb.com/easy-edgedb
Roadmap: edgedb.com/roadmap
pgMustard: pgmustard.com
PyBay: Building a Database with Python Talk: youtube.com

Michael's course on async and await + Cython + uvloop: talkpython.fm/async
Michael's PyBay talk: Flask + HTMX: youtube.com
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon