Low level API¶
Higher level parsing¶
Typically this is called via:
>>> import requirements
>>> requirements.parse('django>=1.5')
-
requirements.parser.
parse
(reqstr: Union[str, TextIO]) → Iterator[requirements.requirement.Requirement][source]¶ Parse a requirements file into a list of Requirements
See: pip/req.py:parse_requirements()
Parameters: reqstr – a string or file like object containing requirements Returns: a generator of Requirement objects
Lower level parsing¶
Under the hood, the Requirement
class does most of the heavy lifting.
-
class
requirements.requirement.
Requirement
(line: str)[source]¶ Represents a single requirement
Typically instances of this class are created with
Requirement.parse
. For local file requirements, there’s no verification that the file exists. This class attempts to be dict-like.See: http://www.pip-installer.org/en/latest/logic.html
Members:
line
- the actual requirement line being parsededitable
- a boolean whether this requirement is “editable”local_file
- a boolean whether this requirement is a local file/pathspecifier
- a boolean whether this requirement used a requirement specifier (eg. “django>=1.5” or “requirements”)vcs
- a string specifying the version control systemrevision
- a version control system specifiername
- the name of the requirementuri
- the URI if this requirement was specified by URIsubdirectory
- the subdirectory fragment of the URIpath
- the local path to the requirementhash_name
- the type of hashing algorithm indicated in the linehash
- the hash value indicated by the requirement lineextras
- a list of extras for this requirement (eg. “mymodule[extra1, extra2]”)specs
- a list of specs for this requirement (eg. “mymodule>1.5,<1.6” => [(‘>’, ‘1.5’), (‘<’, ‘1.6’)])
-
classmethod
parse
(line: str) → requirements.requirement.Requirement[source]¶ Parses a Requirement from a line of a requirement file.
Parameters: line – a line of a requirement file Returns: a Requirement instance for the given line Raises: ValueError on an invalid requirement
-
classmethod
parse_editable
(line: str) → requirements.requirement.Requirement[source]¶ Parses a Requirement from an “editable” requirement which is either a local project path or a VCS project URI.
See: pip/req.py:from_editable()
Parameters: line – an “editable” requirement Returns: a Requirement instance for the given line Raises: ValueError on an invalid requirement
-
classmethod
parse_line
(line: str) → requirements.requirement.Requirement[source]¶ Parses a Requirement from a non-editable requirement.
See: pip/req.py:from_line()
Parameters: line – a “non-editable” requirement Returns: a Requirement instance for the given line Raises: ValueError on an invalid requirement
Misc functions¶
-
requirements.
parse
(reqstr: Union[str, TextIO]) → Iterator[requirements.requirement.Requirement][source]¶ Parse a requirements file into a list of Requirements
See: pip/req.py:parse_requirements()
Parameters: reqstr – a string or file like object containing requirements Returns: a generator of Requirement objects