requirementslib package

class requirementslib.Lockfile(path: pathlib.Path = NOTHING, requirements: list = NOTHING, dev_requirements: list = NOTHING, projectfile: requirementslib.models.project.ProjectFile = NOTHING, lockfile: plette.lockfiles.Lockfile = NOTHING, newlines: str = 'n')[source]

Bases: object

as_requirements(include_hashes=False, dev=False)[source]

Returns a list of requirements in pip-style format

classmethod create(path, create=True)[source]
default
dev_requirements
dev_requirements_list
develop
extended_keys
classmethod from_data(path, data, meta_from_project=True)[source]

Create a new lockfile instance from a dictionary.

Parameters:
  • path (str) – Path to the project root.
  • data (dict) – Data to load into the lockfile.
  • meta_from_project (bool) – Attempt to populate the meta section from the project root, default True.
get(k)[source]
get_deps(dev=False, only=True)[source]
get_requirements(dev=True, only=False)[source]

Produces a generator which generates requirements from the desired section.

Parameters:dev (bool) – Indicates whether to use dev requirements, defaults to False
Returns:Requirements from the relevant the relevant pipfile
Return type:Requirement
classmethod load(path, create=True)[source]

Create a new lockfile instance.

Parameters:
  • project_path (str or pathlib.Path) – Path to project root or lockfile
  • lockfile_name (str) – Name of the lockfile in the project root directory
  • pipfile_path (pathlib.Path) – Path to the project pipfile
Returns:

A new lockfile representing the supplied project paths

Return type:

Lockfile

classmethod load_projectfile(path, create=True, data=None)[source]

Given a path, load or create the necessary lockfile.

Parameters:
  • path (str) – Path to the project root or lockfile
  • create (bool) – Whether to create the lockfile if not found, defaults to True
Raises:
  • OSError – Thrown if the project root directory doesn’t exist
  • FileNotFoundError – Thrown if the lockfile doesn’t exist and create=False
Returns:

A project file instance for the supplied project

Return type:

ProjectFile

lockfile
classmethod lockfile_from_pipfile(pipfile_path)[source]
newlines
path
projectfile
classmethod read_projectfile(path)[source]

Read the specified project file and provide an interface for writing/updating.

Parameters:path (str) – Path to the target file.
Returns:A project file with the model and location for interaction
Return type:ProjectFile
requirements
requirements_list
section_keys
write()[source]
class requirementslib.Pipfile(path: pathlib.Path = NOTHING, projectfile: requirementslib.models.project.ProjectFile = NOTHING, pipfile: requirementslib.models.pipfile.PipfileLoader = NOTHING, pyproject: tomlkit.toml_document.TOMLDocument = NOTHING, build_system: dict = NOTHING, requirements: list = NOTHING, dev_requirements: list = NOTHING)[source]

Bases: object

allow_prereleases
build_backend
build_requires
build_system
dev_packages
dev_requirements
extended_keys
get(k)[source]
get_deps(dev=False, only=True)[source]
classmethod load(path, create=False)[source]

Given a path, load or create the necessary pipfile.

Parameters:
  • path (Text) – Path to the project root or pipfile
  • create (bool) – Whether to create the pipfile if not found, defaults to True
Raises:
  • OSError – Thrown if the project root directory doesn’t exist
  • FileNotFoundError – Thrown if the pipfile doesn’t exist and create=False
Returns:

A pipfile instance pointing at the supplied project

:rtype:: class:~requirementslib.models.pipfile.Pipfile

classmethod load_projectfile(path, create=False)[source]

Given a path, load or create the necessary pipfile.

Parameters:
  • path (Text) – Path to the project root or pipfile
  • create (bool) – Whether to create the pipfile if not found, defaults to True
Raises:
  • OSError – Thrown if the project root directory doesn’t exist
  • FileNotFoundError – Thrown if the pipfile doesn’t exist and create=False
Returns:

A project file instance for the supplied project

Return type:

ProjectFile

packages
path
pipfile
projectfile
classmethod read_projectfile(path)[source]

Read the specified project file and provide an interface for writing/updating.

Parameters:path (Text) – Path to the target file.
Returns:A project file with the model and location for interaction
Return type:ProjectFile
requirements
requires_python
root
write()[source]
class requirementslib.Requirement(name=NOTHING, vcs=None, req=None, markers=None, specifiers=NOTHING, index=None, editable=None, hashes=NOTHING, extras=NOTHING, abstract_dep=None, line_instance=None, ireq=None)[source]

Bases: object

add_hashes(hashes)[source]
as_ireq()[source]
as_line(sources=None, include_hashes=True, include_extras=True, include_markers=True, as_list=False)[source]

Format this requirement as a line in requirements.txt.

If sources provided, it should be an sequence of mappings, containing all possible sources to be used for this requirement.

If sources is omitted or falsy, no index information will be included in the requirement line.

as_pipfile()[source]
build_backend
commit_hash
constraint_line
copy()[source]
extras_as_pip
find_all_matches(sources=None, finder=None)[source]

Find all matching candidates for the current requirement.

Consults a finder to find all matching candidates.

Parameters:
  • sources – Pipfile-formatted sources, defaults to None
  • sources – list[dict], optional
  • finder (PackageFinder) – A PackageFinder instance from pip’s repository implementation
Returns:

A list of Installation Candidates

Return type:

list[ InstallationCandidate ]

classmethod from_ireq(ireq)[source]
classmethod from_line(line)[source]
classmethod from_metadata(name, version, extras, markers)[source]
classmethod from_pipfile(name, pipfile)[source]
get_abstract_dependencies(sources=None)[source]

Retrieve the abstract dependencies of this requirement.

Returns the abstract dependencies of the current requirement in order to resolve.

Parameters:
  • sources – A list of sources (pipfile format), defaults to None
  • sources – list, optional
Returns:

A list of abstract (unpinned) dependencies

Return type:

list[ AbstractDependency ]

get_dependencies(sources=None)[source]

Retrieve the dependencies of the current requirement.

Retrieves dependencies of the current requirement. This only works on pinned requirements.

Parameters:
  • sources – Pipfile-formatted sources, defaults to None
  • sources – list[dict], optional
Returns:

A set of requirement strings of the dependencies of this requirement.

Return type:

set(str)

get_hashes_as_pip(as_list=False)[source]
get_line_instance()[source]
get_markers()[source]
get_name()[source]
get_requirement()[source]
get_specifier()[source]
get_specifiers()[source]
get_version()[source]
hashes_as_pip
ireq
is_direct_url
is_file_or_url
is_named
is_vcs
is_wheel
line_instance
markers_as_pip
merge_markers(markers)[source]
name
normalized_name
pipfile_entry
requirement
run_requires(sources=None, finder=None)[source]
specifiers
update_name_from_path(path)[source]
uses_pep517