python

105 posts tagged “python”.

  1. 2025
  2. Generated a summary of nested JSON data

    I was trying to figure out the shape of the JSON object from https://github.com/simonw/coronavirus-data-gov-archive/blob/master/data latest.json?raw=true - which is 3.2MB and heavily nested, so it's…

    1 min read
  3. macOS Catalina sort-of includes Python 3

    Once you have installed the "command line tools" for Catalina using the following terminal command: xcode-select –install will run Python 3.7.3: % which python3 /usr/bin/python3 % python3 Python 3.7.3…

    1 min read
  4. Embedding paragraphs from my blog with E5-large-v2

    Xeophon suggested that E5-large-v2 as an embedding model that was worth a closer look. It's an interesting model. It's trained to match queries against passages of text.

    6 min read
  5. How to mock httpx using pytest-mock

    I wrote this test to exercise some httpx code today, using pytest-mock. The key was to use which patches the module that was imported by the module.

    1 min read
  6. Using cog to update --help in a Markdown README file

    My csvs-to-sqlite README includes a section that shows the output of the command (relevant issue). I had been manually copying this in, but I decided to try using cog to automate the process.

    1 min read
  7. Debugging a Click application using pdb

    This tip is for when you are working on a Python command-line application that runs using that program's name, as opposed to typing .

    1 min read
  8. Outputting JSON with reduced floating point precision

    datasette-leaflet-geojson outputs GeoJSON geometries in HTML pages in a way that can be picked up by JavaScript and used to plot a Leaflet map.

    1 min read
  9. Geocoding from Python on macOS using pyobjc-framework-CoreLocation

    Rhet Turnbull shared this short script for looking up the named timezone for a given location from Python on macOS using and the framework. It uses the package and pyobjc-framework-CoreLocation.

    1 min read
  10. Conditionally creating directories in cookiecutter

    I wanted my datasette-plugin cookiecutter template to create empty and directories if the user replied to the and prompts.

    1 min read
  11. Installing flash-attn without compiling it

    If you ever run into instructions that tell you to do this: Do not try to do this . It is a trap. For some reason attempting to install this runs a compilation process which can take multiple hours .

    1 min read
  12. Using pprint() to print dictionaries while preserving their key order

    While parsing a CSV file using today I noticed the following surprising result: This output the following: I had expected to preserve the order of keys from the CSV file, since Python has defaulted to…

    1 min read
  13. Build the official Python documentation locally

    First, checkout the cpython repo: $ git clone git@github.com:python/cpython cd into the directory: $ cd cpython/Doc To get a virtual environment with Sphinx and other required tools, run like this: $…

    1 min read
  14. Introspecting Python function parameters

    For https://github.com/simonw/datasette/issues/581 I want to be able to inspect a Python function to determine which named parameters it accepts and send only those arguments.

    1 min read
  15. Async fixtures with pytest-asyncio

    I wanted to use a fixture with that was itsef as function, so that it could execute statements. Since I'm using a file containing I had to use the fixture to get this to work.

    1 min read
  16. How streaming LLM APIs work

    I decided to have a poke around and see if I could figure out how the HTTP streaming APIs from the various hosted LLM providers actually worked. Here are my notes so far.

    2 min read
  17. 2024
  18. Adding project links to PyPI

    I spotted a neat looking project links section on https://pypi.org/project/ExifReader/ Turns out that's added using a key in setup.py, e.g.

    1 min read
  19. Convert a datetime object to UTC without using pytz

    I wanted to convert a datetime object (from GitPython) to UTC without adding the dependency.

    1 min read
  20. Google OAuth for a CLI application

    :warning: The OOB flow described in this document has been scheduled for deprecation by Google. See issue 39 for notes on how to replace it.

    2 min read
  21. Adding Sphinx autodoc to a project, and configuring Read The Docs to build it

    I built a new API reference page today for , using the Sphinx autodoc extension to extract docstrings from the code and use them to build a full class reference.

    3 min read
  22. Creating a dynamic line chart with SVG

    I helped build the tide chart visualizations for Rocky Beaches. I wanted to generate an SVG line representing 24 hours of tide levels.

    2 min read