Skip to content

Instantly share code, notes, and snippets.

View zzzeek's full-sized avatar
💭
SQLAlchemy 2.0 is released!

Michael Bayer zzzeek

💭
SQLAlchemy 2.0 is released!
View GitHub Profile
@zzzeek
zzzeek / benchmark_anonymous_ids.py
Created November 23, 2025 15:12
Benchmark: id() vs uuid.uuid4() vs secrets.token_hex() for SQLAlchemy anonymous labels
"""Benchmark performance of different anonymous identifier generation methods.
This script compares the performance of:
- id() - Python object id (fastest but not globally unique)
- uuid.uuid4() - UUID version 4 (cryptographically random but slower)
- secrets.token_hex() - Cryptographically secure random hex (preferred)
These are relevant for the _anonymous_label.safe_construct() feature where
we need to generate unique identifiers that won't collide.
"""
@zzzeek
zzzeek / mssql_environment_info.txt
Created November 21, 2025 14:14
mssql-python segfault - core dump analysis
# Environment Information
## System
- OS: Fedora Linux 41
- Kernel: 6.17.7-100.fc41.x86_64
- Architecture: x86_64
## Python
- Version: Python 3.14.0
- Location: /opt/python-3.14.0/bin/python3.14
@zzzeek
zzzeek / test.py
Last active June 7, 2023 20:42
issues with pydantic dataclasses / sqlalchemy
from __future__ import annotations
from typing import TYPE_CHECKING
import pydantic.dataclasses
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
@zzzeek
zzzeek / record.sh
Created December 29, 2022 15:01
the record.sh script
#!/usr/bin/env bash
# notes:
# tuning camera: gtk-v4l package, v4l2-ctl
# we also have:
# ffmpeg, mpg123
# linux
#RESOLUTION="640x480"
@zzzeek
zzzeek / gist:d608913fce4d14e924553c91f4c6ecc0
Created June 7, 2022 21:03
list(dict.items()) atomic or not
import threading
def one(obj):
while True:
skip = set()
try:
{k: v for k, v in obj.__dict__.items() if k not in skip}
except RuntimeError as err:
print("%s" % err)
@zzzeek
zzzeek / size.py
Created February 16, 2022 16:07
get the actual recursive size of arbitrary objects
# taken from https://code.activestate.com/recipes/577504/ **plus**
# the comment at https://code.activestate.com/recipes/577504/#c5
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
from reprlib import repr
def total_size(o, handlers={}, verbose=False):
@zzzeek
zzzeek / test.py
Created October 7, 2021 01:52
adapt_on_lookup_mapping demo
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import aliased
from sqlalchemy.orm import declarative_base
@zzzeek
zzzeek / test.py
Last active October 7, 2021 01:52
adapt_on_names demo
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import aliased
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Session
@zzzeek
zzzeek / test.py
Created June 3, 2021 16:29
python 3.10.0b2 segfault
import greenlet
import sqlite3
class _ErrorContainer(object):
error = None
def _expect_raises_fn(fn):
ec = _ErrorContainer()
"""this is getting close but SQLAlchemy is still not instrumenting __init__ such
that it can intercept Pydantic's operations, in particular that list coming
in which it wants to convert to instrumented list.
this probably could be made to work with some more effort but it will
be quite hacky in the end, not really worth it unless there was
some explicit support in pydantic.
"""