A tool for converting between pip-style and pipfile requirements.
Project description
Installation
Install from PyPI:
$ pipenv install --pre requirementslib
Install from Github:
$ pipenv install -e git+https://github.com/techalchemy/requirementslib.git#egg=requirementslib
Summary
RequirementsLib provides a simple layer for building and interacting with requirements in both the Pipfile format and the requirements.txt format. This library was originally built for converting between these formats in Pipenv.
Usage
Importing a lockfile into your setup.py file
You can use RequirementsLib to import your lockfile into your setup file for including your install_requires dependencies:
from requirementslib import Lockfile
lockfile = Lockfile.create('/path/to/project/dir')
install_requires = lockfile.as_requirements(dev=False)
Interacting with a Pipfile directly
You can also interact directly with a Pipfile:
>>> from requirementslib import Pipfile
>>> pf = Pipfile.load('/home/hawk/git/pypa-pipenv')
>>> pf.sections
[Section(name='packages', requirements=[]), Section(name='dev-packages', requirements=[Requirement(name='pipenv', vcs=None, req=FileRequirement(setup_path=None, path='.', editable=True, uri='file:///home/hawk/git/pypa-pipenv', link=<Link file:///home/hawk/git/pypa-pipenv>, name='pipenv', req=<Requirement: "-e file:///home/hawk/git/pypa-pipenv">), markers='', specifiers=None, index=None, editable=True, hashes=[], extras=None),...]
And you can even write it back out into Pipfile’s native format:
>>> print(pf.dump(to_dict=False))
[packages]
[dev-packages]
pipenv = {path = ".", editable = true}
flake8 = ">=3.3.0,<4"
pytest = "*"
mock = "*"
[scripts]
tests = "bash ./run-tests.sh"
[pipenv]
allow_prereleases = true
Create a requirement object from requirements.txt format
>>> from requirementslib import Requirement
>>> r = Requirement.from_line('-e git+https://github.com/pypa/pipenv.git@master#egg=pipenv')
>>> print(r)
Requirement(name='pipenv', vcs='git', req=VCSRequirement(editable=True, uri='git+https://github.com/pypa/pipenv.git', path=None, vcs='git', ref='master', subdirectory=None, name='pipenv', link=<Link git+https://github.com/pypa/pipenv.git@master#egg=pipenv>, req=<Requirement: "-e git+https://github.com/pypa/pipenv.git@master#egg=pipenv">), markers=None, specifiers=None, index=None, editable=True, hashes=[], extras=[])
>>> r.as_pipfile()
{'pipenv': {'editable': True, 'ref': 'master', 'git': 'https://github.com/pypa/pipenv.git'}}
Or move from Pipfile format to requirements.txt:
>>> r = Requirement.from_pipfile(name='pythonfinder', indexes=[], pipfile={'path': '../pythonfinder', 'editable': True})
>>> r.as_line()
'-e ../pythonfinder'
Integrations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file requirementslib-1.3.2.tar.gz.
File metadata
- Download URL: requirementslib-1.3.2.tar.gz
- Upload date:
- Size: 61.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f4f63567070bfa57b2faa50eed943020ecffb3f97bd9ec2644d9b4e15e13d4e
|
|
| MD5 |
e1afd78d3ccb9281a085419e02465d65
|
|
| BLAKE2b-256 |
93d78935ffeb4f3a198862b4eb642f611c2fdff68fddc1627c6dff840bf9c704
|
File details
Details for the file requirementslib-1.3.2-py2.py3-none-any.whl.
File metadata
- Download URL: requirementslib-1.3.2-py2.py3-none-any.whl
- Upload date:
- Size: 58.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
113a899ec85c1abfbc38b196f64d52e6028b834e0fce26da6091ca40b059125d
|
|
| MD5 |
b9aacf161c39aca5cd3fc023d3c5c71d
|
|
| BLAKE2b-256 |
4ff20391bcb099076d222761c1ab8e1b91d880bf768bb3b49e0b451dd16b2567
|