python

105 posts tagged “python”.

  1. 2023
  2. Counting SQLite virtual machine operations

    When SQLite executes a query, it does so by executing a sequence of virtual machine operations. There are mechanisms for cancelling a query after a specific number of these operations, to protect…

    1 min read
  3. Fixing broken text encodings with sqlite-transform and ftfy

    I was working with a database table that included values that were clearly in the wrong character encoding - values like this: Rue Léopold I I used my sqlite-transform tool with the ftfy Python…

    1 min read
  4. A simple pattern for inlining binary content in a Python script

    For simonw/til issue 82 I needed to embed some binary content directly in a Python script. I wanted to wrap that content to fit within 80 columns.

    1 min read
  5. Explicit file encodings using click.File

    I wanted to add a option to which could be used to change the file encoding used to read the incoming CSV or TSV file - see sqlite-utils 182.

    1 min read
  6. Building Mastodon bots with GitHub Actions and toot

    Twitter announced today that they'll be ending free API access for bots. My @covidsewage Twitter bot posts a screenshot of the latest Covid sewage data for parts of the San Francisco Bay Area every…

    2 min read
  7. Relinquishing control in Python asyncio

    in Python is a form of co-operative multitasking, where everything runs in a single thread but asynchronous tasks can yield to other tasks to allow them to execute.

    1 min read
  8. Generating documentation from tests using files-to-prompt and LLM

    I was experimenting with wasmtime-py today and found the current documentation didn't quite give me the information that I needed.

    2 min read
  9. Downloading every video for a TikTok account

    TikTok may or may not be banned in the USA within the next 24 hours or so. Here's a pattern you can use to download all of the videos from a specific account.

    2 min read
  10. Ignoring a line in both flake8 and mypy

    I needed to tell both and to ignore the same line of code. This worked: The order here mattered. This did not get picked up by both tools: noqa: F401 type: ignore But this did: type: ignore noqa: F401

    1 min read
  11. How to call pip programatically from Python

    I needed this for the and commands, see issue 925. My initial attempt at this resulted in weird testing errors ( 928) - while investigating them I stumbled across this comment in the source code: So I…

    1 min read
  12. Helper function for pagination using AWS boto3

    I noticed that a lot of my boto3 code in s3-credentials looked like this: This was enough verbosity that I was hesitating on implementing pagination properly for some method calls.

    1 min read
  13. Use setup.py to install platform-specific dependencies

    For photos-to-sqlite I needed to install as a dependency, but only if the platform is macOS - it's not available for Linux. Here's the magic incantation to do that: So in the install requires line.

    1 min read
  14. Cryptography in Pyodide

    Today I was evaluating if the Python cryptography package was a sensible depedency for one of my projects.

    2 min read
  15. Expanding ChatGPT Code Interpreter with Python packages, Deno and Lua

    Update: Code Interpreter often claims that it can't run binaries uploaded like this, but it looks like it still works if you are are persistent enough with it.

    4 min read
  16. Code coverage using pytest and codecov.io

    I got my asgi-csrf Python package up to 100% code coverage. Here's the pull request. I started by installing and using the pytest-cov pytest plugin.

    1 min read
  17. Deploying the CLIP embedding model on Fly

    I ended up deploying a Datasette instance to Fly.io using my llm-clip and datasette-llm-embed plugins.

    2 min read
  18. Running Python code in a subprocess with a time limit

    I figured out how to run a subprocess with a time limit for datasette-ripgrep, using the method. The pattern looks like this: For datasette-seaborn I wanted to render a chart using the Python seaborn…

    1 min read
  19. Find local variables in the traceback for an exception

    For sqlite-utils issue 309 I had an error that looked like this: And I wanted to display the values of the and variables as part of a custom error message.

    1 min read
  20. git bisect

    I fixed two bugs in Datasette using - a tool which lets you run an automated binary search against a commit log to find the source of a bug.

    1 min read
  21. Defining setup.py dependencies using a URL

    For sqlite-utils issue 464 I implemented a fix to a tiny bug in a dependency in my own fork on GitHub.

    1 min read