Skip to main content

A tool for converting between pip-style and pipfile requirements.

Project description

https://img.shields.io/pypi/v/requirementslib.svg https://img.shields.io/pypi/l/requirementslib.svg https://travis-ci.org/sarugaku/requirementslib.svg?branch=master https://ci.appveyor.com/api/projects/status/hntt25rbnr5yiwmf/branch/master?svg=true https://img.shields.io/pypi/pyversions/requirementslib.svg https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg Documentation Status

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

requirementslib-1.2.2.tar.gz (52.7 kB view details)

Uploaded Source

Built Distribution

requirementslib-1.2.2-py2.py3-none-any.whl (49.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file requirementslib-1.2.2.tar.gz.

File metadata

  • Download URL: requirementslib-1.2.2.tar.gz
  • Upload date:
  • Size: 52.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.0

File hashes

Hashes for requirementslib-1.2.2.tar.gz
Algorithm Hash digest
SHA256 5787961d7ea53f7d97929a73d38a39d360e8999309554f475f93898cc1286222
MD5 f81973550f6b01bf143d15fffaf0b441
BLAKE2b-256 28ec995bf87f35debfc89246f374d720160d606c72fa27ddd9caee375cadc9f7

See more details on using hashes here.

File details

Details for the file requirementslib-1.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: requirementslib-1.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.0

File hashes

Hashes for requirementslib-1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7d277e43b01dfb480a92d51b987d39e3902add16a5a643f5905b84ffe3bc5d68
MD5 50a65431cb076cf3a5e0491f29840db4
BLAKE2b-256 2f4daaa0924a8aa42997ad27828935a36004821883d04c8437520102a65ede3b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page