PyCon EU 2026 in Prague featured a dedicated track on database patterns for modern Python services. UUID v7 was the central theme — with Python 3.13’s uuid.uuid7() making adoption frictionless across FastAPI, Django, and SQLAlchemy. See UUID in Python for the full implementation guide.
Event details
| Conference | PyCon EU 2026 |
| Date | April 23–27, 2026 |
| Location | Prague, Czech Republic |
| Focus | UUID v7 in Python 3.13 — uuid.uuid7(), SQLAlchemy, FastAPI, Django migration |
Key sessions
Python 3.13 uuid.uuid7()
import uuid
# Python 3.13+ — standard library
id = uuid.uuid7()
print(id) # UUID object
print(str(id)) # '018fbe3a-4c5d-7b12-8f3e-1a2b3c4d5e6f'
print(id.version) # 7
# Extract creation timestamp
hex_str = id.hex[:12] # first 12 hex chars = top 48 bits
ms = int(hex_str, 16)
import datetime
created_at = datetime.datetime.fromtimestamp(ms / 1000, tz=datetime.timezone.utc)
See Python 3.13 Adds uuid.uuid7() for the full stdlib announcement.
FastAPI with UUID v7
from fastapi import FastAPI
from pydantic import BaseModel
import uuid
app = FastAPI()
class OrderCreate(BaseModel):
customer_id: uuid.UUID
total: float
class OrderResponse(BaseModel):
id: uuid.UUID
customer_id: uuid.UUID
status: str
@app.post("/orders", response_model=OrderResponse, status_code=201)
async def create_order(body: OrderCreate):
order_id = uuid.uuid7() # Python 3.13+ stdlib
# persist...
return OrderResponse(id=order_id, customer_id=body.customer_id, status="pending")
See UUID in FastAPI.
SQLAlchemy async model
from sqlalchemy import Column, String
from sqlalchemy.dialects.postgresql import UUID as PgUUID
import uuid
class Order(Base):
__tablename__ = "orders"
id = Column(PgUUID(as_uuid=True), primary_key=True, default=uuid.uuid7)
customer_id = Column(PgUUID(as_uuid=True), nullable=False)
status = Column(String, nullable=False, default="pending")
See UUID in SQLAlchemy.
Django UUID v7 primary key
from django.db import models
import uuid
class Order(models.Model):
# Django 5.x — UUIDField with uuid7 default
id = models.UUIDField(primary_key=True, default=uuid.uuid7, editable=False)
customer_id = models.UUIDField(db_index=True)
status = models.CharField(max_length=50, default='pending')
class Meta:
ordering = ['id'] # UUID v7 sort = chronological
See UUID in Django.
Cursor pagination
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
async def list_orders(db: AsyncSession, customer_id: uuid.UUID,
cursor: uuid.UUID | None = None, limit: int = 20):
stmt = select(Order).where(Order.customer_id == customer_id)
if cursor:
stmt = stmt.where(Order.id > cursor) # UUID v7 lexicographic = chronological
stmt = stmt.order_by(Order.id).limit(limit + 1)
result = await db.execute(stmt)
rows = result.scalars().all()
has_more = len(rows) > limit
data = rows[:limit] if has_more else rows
return data, (data[-1].id if has_more else None)
Conference takeaways
uuid.uuid7()in stdlib — no pip install for Python 3.13+; fall back touuid6for older versions- SQLAlchemy
default=uuid.uuid7— called Python-side, works with async and sync sessions - Django
ordering = ['id']— UUID v7 eliminates the need forordering = ['created_at'] - FastAPI Pydantic —
uuid.UUIDtype validates and serializes UUID v7 with no extra config - Zero-downtime migration — dual-write UUID v7 alongside existing integer PK before cutover
Further reading
- UUID in Python — Generation and Validation
- Python 3.13 Adds uuid.uuid7() to the Stdlib
- UUID in FastAPI
- UUID in Django
- UUID in SQLAlchemy
External references
Frequently asked questions
How do I use uuid.uuid7() in Python 3.13?
Python 3.13 added uuid.uuid7() to the standard library. Import and call: import uuid; id = uuid.uuid7(). The result is a uuid.UUID object. For older Python versions, use the uuid6 package: from uuid6 import uuid7; id = uuid7(). See Python 3.13 Adds uuid.uuid7() to the Stdlib.
How do I migrate a Django project from integer to UUID v7 primary keys?
Add a uuid_id = models.UUIDField(default=uuid.uuid7, unique=True) column alongside the existing integer PK. Backfill with a migration. Then swap the primary key in a subsequent migration after backfilling. Avoid changing the PK in a single migration on large tables — use a zero-downtime approach with a dual-write period. See UUID Migration Zero-Downtime Guide.
How does UUID v7 work with SQLAlchemy async?
Use Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid7) in your SQLAlchemy model. In async sessions with AsyncSession, the default function is called Python-side before the INSERT. UUID v7 generation is synchronous (CPU-only) and adds no measurable latency to async handlers. See UUID in SQLAlchemy.