
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
pip-requirements-js
Advanced tools
A pure JavaScript/TypeScript parser for pip requirements files. Process requirements.txt, constraints.txt, or pip-tools' requirements.in – all without ever leaving JavaScript.
pip-requirements-js strictly adheres to pip's documentation of the requirements file format, along with PEP 508 – Dependency specification for Python Software Packages. You can sleep well knowing that no dependency will be misinterpreted (if that ever keeps you up at night).
Full extractions means complete requirement info, such as spec-conforming version constraints and complete validation of the environment marker tree.
To extract all the requirements from a given file, use
parsePipRequirementsFile(fileContent: string): Requirement[]
To extract a requirement from a given line, use
parsePipRequirementsLine(lineContent: string): Requirement | null
(null is returned for lines validly lacking a requirement, e.g. empty or comment-only)
Both functions also accept an optional options
parameter with includeLocations: true
to get source location information:
parsePipRequirementsFile(fileContent: string, options: { includeLocations: true }): WithLocation<Requirement>[]
parsePipRequirementsLine(lineContent: string, options: { includeLocations: true }): WithLocation<Requirement> | null
The WithLocation<T>
wrapper includes data
(the parsed requirement) and location
(with startIdx
and endIdx
indicating the character positions in the source).
In both cases a RequirementsSyntaxError
will be thrown if the provided content contains invalid syntax.
To make use of the resulting data, look up what Requirement
is made up of in types.ts
.
There is also a loose mode, which is oriented for processing partially-written requirements. This is useful when handling live code editor input.
parsePipRequirementsFileLoosely
and parsePipRequirementsLineLoosely
work the same as their full versions, except they return LooseProjectNameRequirement
in place of Requirement
. This means that URL-based requirements are skipped, as are requirements/constraints files.
The loose parsing functions also support the includeLocations
option:
parsePipRequirementsFileLoosely(fileContent: string, options: { includeLocations: true }): WithLocation<LooseProjectNameRequirement>[]
parsePipRequirementsLineLoosely(lineContent: string, options: { includeLocations: true }): WithLocation<LooseProjectNameRequirement> | null
pip-requirements-js is built with the robust parser generator Ohm.js – the core of this library is the pep-508.ohm grammar, which is an Ohm port of PEP 508's complete dependency specification grammar (originally defined for Parsley), with some pip-specific additions (such as the -r extra-requirements.txt
syntax). This ensures the greatest possible compatibility with what pip itself does.
Well, I built this to power my other side project, the VS Code extension PyPI Assistant. Give that a try too!
FAQs
A robust parser for requirements.txt files
The npm package pip-requirements-js receives a total of 2,246 weekly downloads. As such, pip-requirements-js popularity was classified as popular.
We found that pip-requirements-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.