-
Notifications
You must be signed in to change notification settings - Fork 325
Description
Is there an existing issue for this?
- I have searched the existing issues (open and closed), and could not find an existing issue
What keywords did you use to search existing issues?
user agent
Please describe the problem you are attempting to solve with this request
TL;DR: It would be nice to be able to augment twine's user-agent in a controlled, limited way so that PyPI and other indices can see adoption curves on things like gh-action-pypi-publish.
Python uploading clients like twine use linehaul to provide useful metadata to PyPI via their User-Agent headers. For example, twine already does this here:
Lines 332 to 337 in 54b9f22
| s.headers["User-Agent"] = ( | |
| user_agent.UserAgentBuilder("twine", twine.__version__) | |
| .include_implementation() | |
| .build() | |
| ) | |
| return s |
(as do other major uploading clients, e.g. poetry, uv, maturin, etc.)
Uploading tools (and especially twine) are generally wrapped/nested inside of other tools or frameworks. For example, the pypa/gh-action-pypi-publish action is widely used and wraps twine to perform uploads.
It would be nice, on the ecosystem level, to know about these integrations and their adoption curves, similarly to how the ecosystem has insight into the uploading tools themselves!
How do you think we should solve this?
My first thought for addressing this is to add a TWINE_USER_AGENT_QUALIFIER environment variable. This variable would be optional, and could be set by the user (integrator in this case).
The value could be limited in various reasonable ways, e.g. could be limited to UTF-8, fewer than 64 (or whatever) bytes, must be in the form component/version, etc.
When present, twine's user agent would go from:
twine/6.1.0 CPython/3.13.7
to (for example):
twine/6.1.0 CPython/3.13.7 (gh-action-pypi-publish/v1.13.0)
Anything else you'd like to mention?
An alternative to the above would be to move away from plain text user agent, and towards a JSON user agent encoding. For example, pip and uv both use a <TOOL> <JSON> convention that linehaul knows about, e.g. here:
Separately, making this kind of change will probably require some degree of changes to linehaul and other consumers of Python packaging user agent metadata since the current linehaul parser for twine doesn't expect a trailing segment after the implementation segment:
Finally, an alternative to all of the above would be to let users fully override twine's user-agent, e.g. with a TWINE_USER_AGENT variable. However, given that the goal of linehaul is to produce more structured information to help PyPI/Python packaging, I think this wouldn't be super helpful. But I could be underthinking that.