Self-contained Python scripts with uv - the.dusktreader blog
I am working on a Go project to better learn the language. It's a simple API backed by a postgres database. When I need to test out an endpoint, I prefer to use the httpx python package inside an ipython REPL over making curl requests. It's nice to be able to introspect responses and easily package payloads with dicts instead of writing out JSON. Anyway, I decided to write a script to upsert some user data so that I can beat on my /users endpoint. My jam_users.py script looks like this: This is really straight-forward. It will clear out any existing users and then insert these test users. Right after that, I get dropped into an ipython repl to do what I need for testing. All I have to do is run: However, if I want to run the script as-is, I will need to choose one of these approaches: These are both not great options in my opinion. These approaches also rely on having a system python installed that is compatible with these packages. This isn't as big of a problem, but something to cons
Self-contained Python scripts with uv TLDR You can add uv into the shebang line for a Python script to make it a self-contained executable. I am working on a Go project to better learn the language. It's a simple API backed by a postgres database. When I need to test out an endpoint, I prefer to use the httpx python package inside an ipython REPL over making curl requests. It's nice to be able to introspect responses and easily package payloads with dicts instead of writing out JSON. Anyway, I decided to write a script to upsert some user data so that I can beat on my /users endpoint. My jam_u
saved by
related reading
- uvdocs.astral.sh
- Charlie Marsh: uv: An Extremely Fast Python Package Manageryoutube.com
- uv: An extremely Fast Python Package Manager :: Jane Streetjanestreet.com
- uv: An In-Depth Guide to Python's Fast and Ambitious New Package Managersaaspegasus.com
- Using .env Files for Environment Variables in Python Applications - DEV Communitydev.to
- mildbyte.xyz • Solving Wordle with uv's dependency resolvermildbyte.xyz
- Python: Just write SQLjoaodlf.com
- Building a Python Appstevedower.id.au
- GitHub - konstin/sudoku-in-python-packaging: Sudoku solving in python packaginggithub.com
- Doing much better than your .env file | Mediummedium.com
- Build a Simple CRUD App with Python, Flask, and React | Okta Developerdeveloper.okta.com
- Niels Cautaerts - Python dependency management is a dumpster firenielscautaerts.xyz