Skip to main content

twat

Twardoch's Workstation Automation Toolkit. A minimal plugin host for Python: install small, focused packages and access them all through one namespace and one CLI.

twat does nothing on its own. Install plugins, and they snap into place.

How it works

Python has a built-in mechanism for packages to register themselves with a group name — called entry points. twat uses this to build a dynamic namespace: when you access twat.fs, it looks up the twat.plugins entry point named fs, loads the module, and hands it back. No configuration files, no registration steps beyond a normal pip install.

import twat

# twat-fs registered itself as a "twat.plugins" entry point named "fs"
files = twat.fs.list_directory(".")

# twat-cache registered as "cache"
@twat.cache.memoize()
def expensive():
    ...

The CLI works the same way. twat fs list /tmp finds the fs plugin, rewrites sys.argv so the plugin thinks it was called directly, and calls twat_fs.main().

Discovering commands

Every plugin ships a Fire-based CLI with two access shapes:

twat-image gray2alpha input.png output.png   # subcommand form
twat-image-gray2alpha input.png output.png   # dashed form (one script per leaf)

Each leaf (and each command group) is registered as a real console_scripts entry point, so typing twat-<TAB> in your shell offers dozens of completions once you have twat[all] installed:

twat-audio              twat-image-gray2alpha       twat-search-web
twat-audio-normalize    twat-llm-ask                twat-speech-transcribe
twat-fs-upload          twat-os-clipboard           twat-video-probe
... (~90 more)

To wire completion of the twat dispatcher itself:

twat --completions zsh  > ~/.zfunc/_twat       # zsh
twat --completions bash > ~/.local/share/bash-completion/completions/twat
twat --completions fish > ~/.config/fish/completions/twat.fish

Install

pip install twat

twat is an empty host. Install plugins separately:

pip install twat-fs twat-cache twat-os

CLI

twat --help              # show host usage
twat --list              # list installed plugin entry point names
twat --list --available  # list installed twat-* distributions + their plugin
twat --available         # same as `--list --available`
twat --doctor            # import each plugin and report load health
twat <plugin_name> [args...]

# Examples:
twat --list
twat fs list /tmp
twat cache clear

twat --list and twat --available read only distribution/entry-point metadata, so they do not import plugin modules just to show what is installed. twat --available also surfaces twat-* packages that are installed but register no plugin (their plugin column shows -).

twat --doctor is the deliberate exception: it imports every registered plugin to verify it loads, prints one [OK]/[FAIL] line per plugin, and exits non-zero if any plugin is broken — handy in CI after pip install twat[all].

Dispatch works by loading the selected plugin, rewriting sys.argv so the plugin sees twat.<plugin> as its executable name, and calling the plugin module's callable main().

Writing a plugin

No SDK required. A plugin is a normal Python package that declares one entry point.

1. Package structure

twat-myplugin/
├── src/
│   └── twat_myplugin/
│       ├── __init__.py    # Public API — everything here becomes twat.myplugin.*
│       └── __main__.py    # CLI handler — must expose a main() function
├── pyproject.toml
└── README.md

2. Register the entry point (pyproject.toml)

[project.entry-points."twat.plugins"]
myplugin = "twat_myplugin"

This is the only twat-specific line in your entire package.

3. Expose your API (__init__.py)

from importlib import metadata

try:
    __version__ = metadata.version(__name__)
except metadata.PackageNotFoundError:
    __version__ = "0.0.0-dev"

def do_something():
    return "result"

# The CLI dispatcher calls plugin.main() — expose it here
try:
    from .__main__ import main
except ImportError:
    def main() -> None:
        pass

__all__ = ["do_something", "main", "__version__"]

4. Handle CLI calls (__main__.py)

import sys

def main() -> None:
    # sys.argv[0] is already "twat.myplugin" when called via `twat myplugin`
    print(f"Hello from myplugin! Args: {sys.argv[1:]}")
    sys.exit(0)

if __name__ == "__main__":
    main()

Naming conventions

Thing Convention Example
pip package twat-<name> with hyphens twat-myplugin
entry point name lowercase, no prefix myplugin
Python module twat_<name> with underscores twat_myplugin

The entry point name becomes the attribute on twat and the subcommand in the CLI.

How plugin loading works

twat.__getattr__ is called whenever you access an attribute that doesn't exist on the module. It scans the twat.plugins entry point group for a matching name, loads the module, registers it in sys.modules as twat.<name> (so subsequent accesses skip the lookup), and returns it.

If no plugin matches, a PluginError is raised with a clear message.

The CLI entry point (twat.main) intercepts sys.argv, pulls out the plugin name, rewrites sys.argv[0] to twat.<plugin> and sys.argv[1:] to the remaining arguments, then calls the plugin's main(). The plugin never knows it was dispatched through twat.

Documentation

Full documentation (MaterialX/MkDocs) lives in src_docs/md/ and builds to docs/:

  • Architecture — how entry points turn twat.fs into a live module.
  • Writing a plugin — the one line of config that makes any package a plugin.
  • CLI & shell completion — --list, --available, --doctor, and twat-<TAB> setup.
  • The plugins — the full table of twat-* packages.

Build it locally:

cd src_docs && mkdocs build -f mkdocs.yaml   # writes ../docs

Prose follows STYLE_GUIDE.md (hook fast, show don't gesture).

Development

git clone https://github.com/twardoch/twat
cd twat
uv venv && uv sync
pytest -xvs

# or the self-contained hatch path:
uvx hatch test                 # run the test suite
uvx hatch run type-check       # mypy
uvx hatch run lint             # ruff check + format

License

MIT

Metadata

Release files for twat 2.7.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twat 2.7.20
File Size Uploaded Provenance Actions
twat-2.7.20.tar.gz 25.8 kB With provenance Details for twat-2.7.20.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twat 2.7.20
File Interpreter ABI Platform Actions
twat-2.7.20-py3-none-any.whl Python 3 none any Details for twat-2.7.20-py3-none-any.whl

Total release size: 48.2 kB

Release files / twat-2.7.20.tar.gz

Download URL twat-2.7.20.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bdcfb85abbec7f6d1e6dff57b94f0433679eb582adffc87659dfd67df283722b
BLAKE2b-256 checksum
How to use checksums
1500eb757b5a66bd6d33025206e6409de619b0b9bda1a51ab4f761ae530e1c51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / twat-2.7.20-py3-none-any.whl

Download URL twat-2.7.20-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83dec7fb14870611e57cae54641fe641f773a44c3889d723505537679a45328c
BLAKE2b-256 checksum
How to use checksums
49519cfe222b0ebf82f78830d31c1bcd70afbaa803c37aca3c76a26552421599
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for twat 2.7.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for twat-2.7.20.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.7.20 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page