python

105 posts tagged “python”.

  1. 2024
  2. Using C_INCLUDE_PATH to install Python packages

    I tried to install my datasette-bplist plugin today in a fresh Python 3.10 virtual environment on macOS and got this error: Thanks to StackOverflow I figured out a workaround.

    1 min read
  3. Using psutil to investigate "Too many open files"

    I was getting this intermittent error running my Datasette test suite: OSError: Errno 24 Too many open files To figure out what was going on, I used the package and its method.

    1 min read
  4. Tracing every executed Python statement

    Today I learned how to use the Python trace module to output every single executed line of Python code in a program - useful for figuring out exactly when a crash or infinite loop happens.

    1 min read
  5. Using the sqlite3 Python module in Pyodide - Python WebAssembly

    Pyodide provides "Python with the scientific stack, compiled to WebAssembly" - it's an incredible project which lets you run a full working Jupyter notebook, complete with complex packages such as…

    1 min read
  6. Upgrading a pipx application to an alpha version

    I wanted to upgrade my git-history installation to a new alpha version. doesn't work for that, because it upgrades to the most recent stable version - but I wanted the alpha.

    1 min read
  7. Streaming indented output of a JSON array

    I wanted to produce the following output from a command-line tool: But I wanted to do it from a streaming iterator - without first buffering the entire output in an in-memory Python list and calling…

    1 min read
  8. Exploring ColBERT with RAGatouille

    I've been trying to get my head around ColBERT. ColBERT is a fast and accurate retrieval model, enabling scalable BERT-based search over large text collections in tens of milliseconds.

    5 min read
  9. Handling CSV files with wide columns in Python

    Users were reporting the following error using to import some CSV files: csv.Error: field larger than field limit (131072) It turns out the Python standard library CSV module enforces a default field…

    1 min read
  10. Getting Python MD5 to work with FIPS systems

    This issue by Parand Darugar pointed out that Datasette doesn't currently run on Linux systems with FIPS enabled, due to the way it uses MD5 hashes. I hadn't heard of FIPS before.

    2 min read
  11. Fixes for datetime UTC warnings in Python

    I was getting the following warning for one of my Python test suites: I also saw a deprecation warning elsewhere for my usage of .

    1 min read
  12. __init_subclass__

    David Beazley on Twitter said: I think 95% of the problems once solved by a metaclass can be solved by instead This inspired me to finally learn how to use it!

    1 min read
  13. Calculating embeddings with gtr-t5-large in Python

    I've long wanted to run some kind of large language model on my own computer. Now that I have a M2 MacBook Pro I'm even more keen to find interesting ways to keep all of those CPU cores busy.

    4 min read
  14. Back-dating Git commits based on file modification dates

    https://www.w3.org/History/1991-WWW-NeXT/Implementation/ It's served up as a browseable Apache directory listing, but that's not the most delightful way to browse code - clicking a link to a file…

    2 min read
  15. The location of the pip cache directory

    uses a cache to avoid downloading packages again: The command can be used to find the location of that cache on your system: Wheels are cached in - in a nested set of folders based on a hash, for…

    1 min read
  16. A simple Python wrapper for the ChatGPT API

    OpenAI released an API for ChatGPT yesterday. It's 1/10th of the price of the model! Their official openai Python package has been upgraded to add support for it (in this commit).

    1 min read
  17. Quickly testing code in a different Python version using pyenv

    I had a bug that was only showing up in CI against Python 3.8. I used the following pattern with pyenv to quickly run the tests against that specific version.

    1 min read
  18. Testing different Python versions with uv with-editable and uv-test

    A quick recipe I figured out today, for running the tests for a project against multiple Python versions. The key command option is .

    1 min read
  19. Safely outputting JSON

    Carelessly including the output of in an HTML page can lead to an XSS hole, thanks to the following: Jinja has a function that avoids this in - the (simplified) implementation looks like this: Which…

    1 min read
  20. The pdb interact command

    Today Carlton told me about the interact command in the Python debugger. Here's how to use it with (but it works anywhere else where you find yourself in a session).

    1 min read
  21. Custom Jinja template tags with attributes

    I decided to implement a custom Jinja template block tag for my datasette-render-markdown plugin. I wanted the tag to work like this: A basic Jinja extension After some fiddling around with GitHub…

    2 min read