pypi_json
¶
PyPI JSON API client library.
Classes:
|
A client for fetching package information from a Python JSON API. |
|
Represents a project’s metadata from the PyPI JSON API. |
Data:
The User-Agent header used for requests; not used when the user provides their own session object. |
-
class
PyPIJSON
(endpoint='https://pypi.org/pypi', auth=None, session=None)[source]¶ A client for fetching package information from a Python JSON API.
If necessary, login/authentication details for the repository can be specified at initialization by setting the
auth
parameter to either a(username, password)
pair or another authentication object accepted by requests.If more complicated session configuration is desired (e.g., setting up caching), the user must create and configure a
requests.Session
object appropriately and pass it to the constructor as thesession
parameter.A
PyPIJSON
instance can be used as a context manager that will automatically close its session on exit, regardless of where the session object came from.- Parameters
endpoint (
Union
[str
,URL
]) – The base URL of the JSON API to query; defaults to the base URL for PyPI’s simple API. If this is aRequestsURL
object, andsession
orauth
are not provided, the values are taken from theRequestsURL
object. Default'https://pypi.org/pypi'
.auth (
Optional
[Any
]) – Optional login/authentication details for the repository; either a(username, password)
pair or another authentication object accepted by requests. DefaultNone
.session (
Optional
[Session
]) – Optionalrequests.Session
object to use instead of creating a fresh one. DefaultNone
.
Attributes:
The timeout for HTTP requests, in seconds.
The
apeye.requests_url.TrailingRequestsURL
object representing the PyPI JSON API, with an authenticated requests session.The URL of the JSON API endpoint.
Methods:
__repr__
()Returns a string representation of the
PyPIJSON
object.get_metadata
(project[, version])Returns metadata for the given project on PyPI.
download_file
(url)Download the file with the given URL from PyPI.
-
endpoint
¶ Type:
TrailingRequestsURL
The
apeye.requests_url.TrailingRequestsURL
object representing the PyPI JSON API, with an authenticated requests session.
-
get_metadata
(project, version=None)[source]¶ Returns metadata for the given project on PyPI.
- Parameters
- Raises
packaging.requirements.InvalidRequirement
if the project cannot be found on PyPI.requests.HTTPError
if an error occurs when communicating with PyPI.
- Return type
-
namedtuple
ProjectMetadata
(info, last_serial, releases=None, urls=(), vulnerabilities=[])[source]¶ Bases:
NamedTuple
Represents a project’s metadata from the PyPI JSON API.
- Fields
info (
ProjectInfoDict
) – Generic information about a specific version of a project.last_serial (
int
) – Monotonically increasing integer sequence that changes every time the project is updated.releases (
Optional
[Dict
[str
,List
[DistributionPackageDict
]]]) – A mapping of version numbers to a list of artifacts associated with a version. .. versionchanged:: 0.3.0 Can now beNone
, as the JSON API no longer includes this key in queries for a specific version.urls (
List
[DistributionPackageDict
]) – A list of release artifacts associated with this version.vulnerabilities (
List
[VulnerabilityInfoDict
]) – Details of vulnerabilities from the Open Source Vulnerabilities project. (New in version 0.2.0)
Attributes:
Methods:
Returns the version number of the latest release on PyPI for this project.
Returns a dictionary mapping PyPI release versions to download URLs and the sha256sum of the file contents.
Returns a dictionary mapping PyPI release versions to download URLs.
get_wheel_tag_mapping
([version])Constructs a mapping of wheel tags to the download URL of the wheel with relevant tag.
-
get_latest_version
()[source]¶ Returns the version number of the latest release on PyPI for this project.
Version numbers are sorted using the rules in PEP 386.
- Return type
-
get_releases_with_digests
()[source]¶ Returns a dictionary mapping PyPI release versions to download URLs and the sha256sum of the file contents.
-
get_wheel_tag_mapping
(version=None)[source]¶ Constructs a mapping of wheel tags to the download URL of the wheel with relevant tag.
This can be used alongside
packaging.tags.sys_tags()
to select the best wheel for the current platform.
-
USER_AGENT
¶ Type:
str
The User-Agent header used for requests; not used when the user provides their own session object.
The structure of the User-Agent is:
' '.join([ f"pypi-json/{__version__} (https://github.com/repo-helper/pypi-json)", f"requests/{requests.__version__}", f"{platform.python_implementation()}/{platform.python_version()}", # ^^^ e.g. CPython ^^^ e.g. 3.8.10 ])
This global attribute should not be changed by other code.