pypi

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pypi fetches package metadata from a Python package index using the JSON API. It pools connections, retries transient failures with exponential backoff, and can fetch many releases concurrently. A Source interface lets the resolver run against the network client or an in-memory source in tests.

Index

Constants

View Source
const DefaultBaseURL = "https://pypi.org/pypi"

DefaultBaseURL is the JSON API root of the public Python Package Index.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a package or release does not exist.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client fetches metadata from a JSON package index.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a client with connection pooling suited to fetching many small metadata documents.

func (*Client) FetchReleases

func (c *Client) FetchReleases(ctx context.Context, refs []Ref, concurrency int) []Result

FetchReleases fetches many releases concurrently, bounded by concurrency. The results are returned in the same order as refs.

func (*Client) Release

func (c *Client) Release(ctx context.Context, name string, v *version.Version) (*ReleaseInfo, error)

Release returns the metadata for a specific version.

func (*Client) Versions

func (c *Client) Versions(ctx context.Context, name string) ([]*version.Version, error)

Versions returns the parseable versions of a package, ascending. Unparseable version strings in the index are skipped rather than failing the whole call.

type MemSource

type MemSource struct {
	// contains filtered or unexported fields
}

MemSource is an in-memory Source. It backs tests and offline resolution from a local set of packages, such as a wheelhouse referenced with find-links.

func NewMemSource

func NewMemSource() *MemSource

NewMemSource creates an empty in-memory source.

func (*MemSource) Add

func (m *MemSource) Add(info *ReleaseInfo)

Add records a release. The package name is canonicalized for lookup.

func (*MemSource) AddPackage

func (m *MemSource) AddPackage(name, ver string, deps ...string) error

AddPackage is a convenience for registering a release from strings.

func (*MemSource) Release

func (m *MemSource) Release(_ context.Context, name string, v *version.Version) (*ReleaseInfo, error)

Release returns the metadata for a specific version.

func (*MemSource) Versions

func (m *MemSource) Versions(_ context.Context, name string) ([]*version.Version, error)

Versions returns the versions of a package, ascending.

type Option

type Option func(*Client)

Option configures a Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL sets the JSON API root, for a mirror or a private index.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient supplies a custom HTTP client.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets how many times a transient failure is retried.

func WithMinBackoff

func WithMinBackoff(d time.Duration) Option

WithMinBackoff sets the initial backoff delay, which doubles per retry.

type Ref

type Ref struct {
	Name    string
	Version *version.Version
}

Ref names a specific release to fetch.

type ReleaseInfo

type ReleaseInfo struct {
	Name           string
	Version        *version.Version
	RequiresPython string
	RequiresDist   []*requirement.Requirement
	Yanked         bool
}

ReleaseInfo is the metadata gopip needs about one release of a package.

type Result

type Result struct {
	Ref  Ref
	Info *ReleaseInfo
	Err  error
}

Result pairs a Ref with its fetched metadata or an error.

type Source

type Source interface {
	// Versions returns all available versions of a package, ascending.
	Versions(ctx context.Context, name string) ([]*version.Version, error)
	// Release returns the metadata for a specific version.
	Release(ctx context.Context, name string, v *version.Version) (*ReleaseInfo, error)
}

Source provides package versions and release metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL