I've been doing advent of code again this year. There are two Python features I always rely on, iterators and pattern matching. Iterators allow for operations on each of its elements without allocating memory for a collection. Ever since pattern matching was introduced in Python 3.10, it's been particularly …
read morePython-in-Python Sandboxing LLM Generated Code
I've been experimenting with Langchain for GPT based queries. One problem we often encounter with GPT is hallucinations. This makes certain classes of problems unsuited to GPT, one example is maths and statistics. Whilst there are improvements for recent models often the maths cannot be trusted.
When I try to …
read moreMy SQLAlchemy Cookbook
I've worked with SQLAlchemy for a while now, and in my opinion it's the best ORM in Python. It's feature rich with strong support for all major databases. And it maintains the SQL feel without losing things like typing.
However there are some challenges here. Despite having very nice documentation …
read moreTypedDicts are better than you think
TypedDict
was introduced in PEP-589 which landed in Python 3.8.The primary use case was to create type annotations for dictionaries. For example,
class Movie(TypedDict): title: str movie: Movie = {"title": "Avatar"}
I remember thinking at the time that this was pretty neat, but I tend to use
read moredataclass …
Closing Python Iterators
I recently came across a video by mcoding about Python iterators' unfortunate closing behaviour.
To sum up the video, when an iterator is interrupted we intuitively we would expect the exit of a context manager or a finally block to be called but that's not necessarily the case. For example …
read moreFree Threaded Python With Asyncio
My First Blog Post
My name is Jamie Chang, I'm a software engineer in London. I like all things Python, but I'll try to mix it up sometimes. I decided to start this blog to get some of the ideas out from my head and to practice communicating technical topics.
For this site, I'm …
read more