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 / 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.
"""
@zzzeek
zzzeek / test.py
Last active January 1, 2021 16:54
async sqlalchemy w/ yappi
import asyncio
import contextlib
import random
import yappi
# install sqlalchemy from github master:
# pip install git+https://github.com/sqlalchemy/sqlalchemy/
from sqlalchemy import cast
from sqlalchemy import Column
@zzzeek
zzzeek / A1_all_sqlalchemy.py
Last active January 27, 2022 09:10
comparing SQLAlchemy 1.4 async to "databases"
import asyncio
import contextlib
import cProfile
import io
import pstats
import random
from sqlalchemy import cast
from sqlalchemy import Column
from sqlalchemy import Integer