Best Practices in Modern Python

Column: Best Practices in Modern Python

Raymond E Peck III
2 min readJul 2, 2024

The Python language, its libraries, and its tools have undergone some fairly radical changes in recent years. The slow introduction of typing and static analysis, increased power of introspection, and many other changes have made Python a more expressive, powerful, and safe language. This column is intended to present a set of best practices in modern Python in a coherent and approachable way for those who have experience with the language, but don’t keep up with the latest.

I recently began this series with a sequence of four posts that covered building a database-backed REST API using FastAPI and SQLModel (which builds on Pydantic and SQLAlchemy). It introduces some of these new features, including using introspection to make our code more declarative. It also shows how to write tests for such a system that can execute with or without a running instance of the server.

The code is available under the Apache 2 #opensource license here:

https://github.com/rpeck/medium

I’ve got a list of additional topics I plan to layer on top of this work. I don’t want to bias the audience, so if there are additional topics you’d like to see, please comment below.

In addition, I did some contracting work on a computer vision product in which I really dug in on static type analysis (for code safety), and using introspection to add runtime safety to Python code. Let me know if you’d like to read about that!

--

--

Raymond E Peck III

Doing software for ML since 2014: H2O.ai, Quantifind, dotData, and Alteryx. Lots of different kinds of startups since co-founding Pure Software (1995 IPO).