#####################
 Running applications
#####################

``pipx run`` downloads and runs a Python application in a one-time, temporary environment, then leaves your system
untouched. Reach for it to scaffold a new project, check an app's help text, or try a tool without committing to an
install.

*************
 Basic usage
*************

.. code-block:: console

    $ pipx run pycowsay moo

pipx installs the package in an isolated, temporary directory and invokes the app:

.. code-block:: console

    $ pipx run pycowsay moo
      ---
    < moo >
      ---
       \   ^__^
        \  (oo)\_______
           (__)\       )\/\
               ||----w |
               ||     ||

Arguments after the app name pass straight through to it:

.. code-block:: console

    $ pipx run pycowsay these arguments all go to pycowsay

*********************
 Ambiguous arguments
*********************

On Python 3.11, pipx can swallow an argument meant for the app when it looks like one of pipx's own options:

.. code-block:: console

    $ pipx run pycowsay --py
    pipx run: error: ambiguous option: --py could match --python-args, --pypackages, --python

Put ``--`` before the app name to forward everything after it verbatim:

.. code-block:: console

    $ pipx run -- pycowsay --py

**********************************
 When the app name differs
**********************************

Some packages expose an app under a different name, or expose several. Use ``--spec`` to name the package and the app
separately:

.. code-block:: console

    $ pipx run --spec PACKAGE APP

Under the pip backend, pipx lists the executables of a package when you guess wrong. `esptool
<https://github.com/espressif/esptool>`_ 4.6.2 ships no ``esptool`` script:

.. code-block:: console

    $ pipx run --spec esptool==4.6.2 esptool
    'esptool' executable script not found in package 'esptool'.
    Available executable scripts:
        esp_rfc2217_server.py - usage: 'pipx run --spec esptool==4.6.2 esp_rfc2217_server.py [arguments?]'
        espefuse.py - usage: 'pipx run --spec esptool==4.6.2 espefuse.py [arguments?]'
        espsecure.py - usage: 'pipx run --spec esptool==4.6.2 espsecure.py [arguments?]'
        esptool.py - usage: 'pipx run --spec esptool==4.6.2 esptool.py [arguments?]'

Run the one you want with ``--spec``:

.. code-block:: console

    $ pipx run --spec esptool==4.6.2 esptool.py

Package authors can remove this requirement by declaring a :doc:`pipx.run entry point
<../explanation/making-packages-compatible>` in their metadata.

.. _tutorial-run-cache:

***********
 Run cache
***********

pipx caches each ``pipx run`` environment for 14 days so repeated runs skip the install. After the cache expires, the
next run fetches the latest version. Under the uv backend pipx hands the run to ``uv tool run``, so `uv
<https://docs.astral.sh/uv/>`_'s own cache applies instead.

.. mermaid::

    flowchart LR
        RUN["pipx run APP"] --> CHECK{"cached?"}
        CHECK -->|"no"| FETCH["fetch + build venv"]
        FETCH --> CACHE["cache venv"]
        CHECK -->|"yes"| REUSE["reuse cached venv"]
        CACHE --> REUSE
        REUSE --> EXPIRE["expires after 14 days"]
        EXPIRE --> RUN

        classDef step fill:#2a9d8f,stroke:#1f7268,color:#fff;
        classDef decide fill:#c78c20,stroke:#946716,color:#fff;
        class RUN,FETCH,CACHE,REUSE,EXPIRE step;
        class CHECK decide;

Force a rebuild before the cache expires with ``--refresh``, which replaces that app's cached environment and keeps the
replacement:

.. code-block:: console

    $ pipx run --refresh APP

``--no-cache`` also rebuilds, but under the pip backend marks the new environment for cleanup by a later run. The two
options are mutually exclusive.

Show the cache directory or remove pipx's cached run environments:

.. code-block:: console

    $ pipx cache dir
    $ pipx cache purge

For how pipx decides what to cache and when, see :doc:`How pipx works <../explanation/how-pipx-works>`.

************
 Learn more
************

- :doc:`Use the uv backend <../how-to/use-uv-backend>`: run with ``uv``, which keeps its own ephemeral cache.
- :doc:`../reference/cli`: every ``pipx run`` flag, including ``--python-args`` and ``--with``.
