---
title: "Python CLI and SDK on PyPI for agents | Agent Ready Checklist"
description: "Declare the command in the [project.scripts] table of pyproject.toml, publish through PyPI Trusted Publishing, and show pip install, uvx and pipx run."
canonical: https://agentreadychecklist.com/guides/put-a-python-cli-on-pypi
site: "Agent Ready Checklist"
last_updated: 2026-11-22
date: 2026-11-22
section: "Guides"
---

# Python CLI and SDK on PyPI for agents | Agent Ready Checklist

> Declare the command in the [project.scripts] table of pyproject.toml, publish through PyPI Trusted Publishing, and show pip install, uvx and pipx run.

Source: https://agentreadychecklist.com/guides/put-a-python-cli-on-pypi
Site: Agent Ready Checklist
Last reviewed: 2026-11-22
Agent endpoints: https://agentreadychecklist.com/llms.txt (index), https://agentreadychecklist.com/openapi.json (API), https://agentreadychecklist.com/mcp (MCP server), https://agentreadychecklist.com/ask (search)
Access: https://agentreadychecklist.com/auth.md (no key). Pricing: https://agentreadychecklist.com/pricing.md (free).

# One project.scripts line gives agents a command to run

Declare the command in the \[project.scripts\] table of pyproject.toml, publish from GitHub Actions through PyPI Trusted Publishing, and show three lines in the docs: pip install, uvx and pipx run. Trusted Publishing replaces manually generated API tokens with short-lived tokens minted over OpenID Connect, and the publish job needs the id-token: write permission.

AR-ACT-06 in the [AgentReady spec](https://github.com/agentready-org/standard/blob/main/spec/spec.md) says SDKs and a CLI should be published, calling them "the forms agents act in, code and shell," and its best practice is to publish SDKs on npm and PyPI and a CLI, with install and first call shown in the docs. A CLI also satisfies AR-ACT-10, which says a product agents are expected to act on must expose at least one interface an agent can act through (an MCP server or a CLI) and names the CLI as the interface that serves agents working in a shell.

Related: [AR-ACT-06](https://agentreadychecklist.com/checklist/ar-act-06/)

Related: [AR-ACT-10](https://agentreadychecklist.com/checklist/ar-act-10/)

## Declare the package and its command in pyproject.toml

Most build backends read a project's basic metadata from the \[project\] table. A minimal file with one command, built from the examples in [Writing your pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/), looks like this:

```toml
[project]
name = "spam-eggs"
version = "2020.0.0"
requires-python = ">=3.8"

[project.urls]
Documentation = "https://readthedocs.org"
Repository = "https://github.com/me/spam.git"

[project.scripts]
spam-cli = "spam:main_cli"
```

Of these fields, name is required and is the only one that cannot be marked as dynamic, while requires-python declares the minimum version of Python you support. Once the project is installed, the spam-cli command is available, and running it does the equivalent of `import sys; from spam import main_cli; sys.exit(main_cli())`. For a callable in a submodule, use an object reference such as `spam.cli:main`; the part before the colon names the module to import, and the part after it identifies the callable. The callable is invoked with no arguments.

A \[build-system\] table tells pip and build which backend to use, and the [Packaging Python Projects tutorial](https://packaging.python.org/en/latest/tutorials/packaging-projects/) gives `requires = ["hatchling >= 1.26"]` with `build-backend = "hatchling.build"` for Hatchling. On requires-python, the tutorial notes that an installer like pip will look back through older versions of packages until it finds one with a matching Python version. From the directory where pyproject.toml is located, `python3 -m build` produces a .tar.gz source distribution and a .whl built distribution in dist/. You should always upload a source distribution and provide built distributions for the platforms your project is compatible with.

Each console\_scripts entry point in the [entry points specification](https://packaging.python.org/en/latest/specifications/entry-points/) refers to a function, and when pip or another console\_scripts aware installer installs the distribution, it creates a command-line wrapper for each entry point. Your function may return an integer to be used as the process exit code; returning None is equivalent to returning 0. Install tools set up these wrappers in the scripts directory of the install scheme but are not responsible for putting that directory on PATH.

## Add a --json flag

Give the command a `--json` flag so an agent working in a shell can ask for structured output instead of text. On/off flags are one of the argument kinds the argparse [add\_argument method](https://docs.python.org/3/library/argparse.html) supports. With `action='store_true'`, the option stores True when given and defaults to False when absent, and `parse_args()` places the parsed values in a Namespace object. Declare `parser.add_argument('--json', action='store_true')` and branch on `args.json` in the function your script entry points to.

To produce the output, [json.dumps](https://docs.python.org/3/library/json.html) serializes an object to a JSON formatted str. Pass `indent` to pretty-print, or `separators=(',', ':')` for the most compact JSON; with `sort_keys=True`, dictionaries are output sorted by key.

## Publish from GitHub Actions with Trusted Publishing

[PyPI's Trusted Publishing](https://docs.pypi.org/trusted-publishers/) uses OpenID Connect to exchange short-lived identity tokens between a trusted third-party service and PyPI, and it eliminates the need for manually generated API tokens when publishing. GitHub Actions can submit an OIDC token to PyPI, which mints an API token for the projects that trust that configuration. That minted token behaves like a normal project-scoped API token but is only valid for 15 minutes from creation, while PyPI's normal API tokens are long-lived.

Only tag pushes trigger the publishing job in [PyPA's GitHub Actions guide](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/):

```yaml
publish-to-pypi:
  if: startsWith(github.ref, 'refs/tags/')
  needs:
  - build
  runs-on: ubuntu-latest
  environment: pypi
  permissions:
    id-token: write
  steps:
  - uses: actions/download-artifact@v6
    with:
      name: python-package-distributions
      path: dist/
  - uses: pypa/gh-action-pypi-publish@release/v1
```

Before the first run, set up the publisher at `https://pypi.org/manage/account/publishing/`: enter the PyPI project name, the GitHub repository owner and name, the workflow file name, and the GitHub Environment name (pypi). A "pending" publisher creates the project automatically the first time it is used. For security reasons, you must require manual approval on each run for the pypi environment. Keep the build job separate from the publishing jobs; the build job stores dist/ with actions/upload-artifact, and the publish step uploads the contents of dist/ into PyPI unconditionally. Starting with version v1.11.0, pypa/gh-action-pypi-publish generates and uploads PEP 740 attestations for each distribution by default. Old PYPI\_API\_TOKEN and TEST\_PYPI\_API\_TOKEN secrets are obsolete: remove them from the repository and revoke them on PyPI and TestPyPI.

You must provide the `id-token: write` permission at the job level (strongly recommended) or the workflow level (discouraged), as [PyPI's publisher guide](https://docs.pypi.org/trusted-publishers/using-a-publisher/) puts it. Without it, the publishing action cannot identify itself to PyPI. Specifying a GitHub environment is optional but strongly encouraged.

## Set project URLs for the PyPI page

All URLs from \[project.urls\] appear together on the project page, with those verified at the time of upload marked and the full set exposed through the JSON API, according to [PyPI's project metadata docs](https://docs.pypi.org/project_metadata/). For packages uploaded with GitHub Actions from a repository, Trusted Publishing verifies the GitHub URLs for that repository; for pypa/pip these include `https://github.com/pypa/pip`, its subpaths, the .git URL and `https://pypa.github.io/pip`.

Verification, PyPI warns, only attests that the package owner controlled the URL at the time of upload, and says nothing about its current safety, ownership or relationship to the project. It is not repeated after upload, and a URL can change hands, change content or stop working and still display as verified.

Icons come from the first rule in PyPI's table that matches a link's label or domain, and label matching is case-insensitive. Labels such as Changelog or History get the changelog icon, while Repository or Source Code gets the source icon only when no earlier rule, such as the github.com domain rule, matches first. In pyproject.toml, the [pyproject.toml guide](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) says a label containing spaces must be quoted, and labels that are not well-known, such as MyHomepage, are rendered verbatim.

## How an agent runs the command

For a one-off run, uvx invokes a tool without installing it and is exactly equivalent to `uv tool run`, per [uv's tool guide](https://docs.astral.sh/uv/guides/tools/). Tools run this way are installed into temporary, isolated environments. `uvx ruff` installs the ruff package, which provides the ruff command; when the package and command names differ, use `--from`, as in `uvx --from httpie http`.

Repeated use calls for `uv tool install`, which puts the tool in a persistent environment and places its executables in a bin directory in the PATH. If that directory is not on PATH, uv displays a warning, and `uv tool update-shell` can add it. Installing a tool does not make its modules available in the current environment.

Each application gets its own virtual environment under [pipx](https://pipx.pypa.io/stable/), which installs and runs end-user Python applications in isolated environments. It uses uv when available and pip otherwise, and pulls packages from PyPI by default. `pipx run` runs the latest version of an app in a temporary environment without installing it first. Any package that declares console script entry points works with pipx, which fills the same role as JavaScript's npx.

Related: [How to put a CLI on npm](https://agentreadychecklist.com/guides/put-a-cli-on-npm/)

## Put the install lines in the docs

Spell each line the way its tool prints it, with your package and command names in place of the placeholders. The short uvx form works when the package provides a command of the same name, as [uv's tool guide](https://docs.astral.sh/uv/guides/tools/) shows with ruff:

```text
pip install <package>
uvx <command>
pipx run <command>
```

Related: [Docs for AI agents](https://agentreadychecklist.com/guides/docs-for-ai-agents/)

## Sources

-   [AgentReady spec](https://github.com/agentready-org/standard/blob/main/spec/spec.md)AgentReady standard repository, read 2026-11-22
-   [Writing your pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/)Python Packaging Authority, read 2026-11-22
-   [Packaging Python Projects](https://packaging.python.org/en/latest/tutorials/packaging-projects/)Python Packaging Authority, read 2026-11-22
-   [Entry points specification](https://packaging.python.org/en/latest/specifications/entry-points/)Python Packaging Authority, read 2026-11-22
-   [Publishing package distribution releases using GitHub Actions CI/CD workflows](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)Python Packaging Authority, read 2026-11-22
-   [Publishing to PyPI with a Trusted Publisher](https://docs.pypi.org/trusted-publishers/)PyPI, read 2026-11-22
-   [Publishing with a Trusted Publisher](https://docs.pypi.org/trusted-publishers/using-a-publisher/)PyPI, read 2026-11-22
-   [Project metadata (PyPI docs)](https://docs.pypi.org/project_metadata/)PyPI, read 2026-11-22
-   [Using tools (uv)](https://docs.astral.sh/uv/guides/tools/)Astral (uv docs), read 2026-11-22
-   [pipx](https://pipx.pypa.io/stable/)PyPA (pipx), read 2026-11-22
-   [argparse: Parser for command-line options](https://docs.python.org/3/library/argparse.html)Python Software Foundation, read 2026-11-22
-   [json: JSON encoder and decoder](https://docs.python.org/3/library/json.html)Python Software Foundation, read 2026-11-22

Edition

Data

2026-11-04

Reviewed

2026-11-22

Spec

AgentReady v2.0.1, db79f10

Crawl

13,071 rows, 2026-11-04

Ora

132 checks, contract 1.38.0, 2026-11-05

Verify with Ora

The scanner this site recommends for the whole checklist. 132 checks, a score out of 100, no account.

`npx ax@0.10 audit <url> --min-score <n>`

[Why Ora, and its limits](https://agentreadychecklist.com/verify-with-ora/)

Method

-   [How rows, commands and rates are made](https://agentreadychecklist.com/method/)
-   [How an Ora check is matched to a row](https://agentreadychecklist.com/checklist/ora-checks/)
-   [Pass rates by rank band](https://agentreadychecklist.com/data/by-rank/)

Sources and read dates sit at the foot of the page.

Last reviewed 2026-11-22. AgentReady v2.0.1, read 2026-11-24.
