dephell deps convert

Convert dependencies between formats. Dephell will automagically lock them if needed and resolve all conflicts.

Dephell uses four pieces of information for conversion:

  1. --from-format: The format to convert from (e.g. poetry)
  2. --from-path: The path to the file to read from (e.g. pyproject.toml)
  3. --to-format: The format to convert to (e.g. setuppy)
  4. --to-path: The path to the file where the result should be put (e.g. You can provide the special case ‘stdout’ to this option to output to the screen instead of a file.

Dephell can try to guess the formats or paths you want to use given the other piece of information, giving you three different ways to specify what you want:

  1. Explicitly specify path and format: --from-format=poetry --from-path=pyproject.toml and --to-format=setuppy
  2. Specify only path: --from=pyproject.toml and
  3. Specify only format: --from=poetry and --to=setuppy.

Supported formats

  1. Archives:
    1. *.egg-info (egginfo)
    2. *.tar.gz (sdist)
    3. *.whl (wheel)
  2. pip:
    1. requirements.txt (pip)
    2. requirements.lock (piplock)
  3. pipenv:
    1. Pipfile (pipfile)
    2. Pipfile.lock (pipfilelock)
  4. poetry:
    1. pyproject.toml (poetry)
    2. poetry.lock (poetrylock)
  5. Environment:
    1. Imports in the package (imports). Pass path to package or module and dephell will automatically detect required packages.
    2. Installed packages (installed). It works like pip freeze. Dephell can only read from this format, of course. If you want to install packages, use install command.
  6. Other:
    1. (setuppy)
    2. flit (flit)
    3. conda’s environment.yml (conda)
    4. pyproject.toml build-system requires (pyproject)


Lock dependencies for Pipfile:

$ dephell deps convert --from=Pipfile --to=Pipfile.lock

Or the same, but more explicit:

$ dephell deps convert \
    --from-format=pipfile --from-path=Pipfile \
    --to-format=pipfilelock --to-path=Pipfile.lock

Best practice is specify your dependencies file in pyproject.toml DepHell config:

from = {format = "pipfile", path = "Pipfile"}
to = {format = "pipfilelock", path = "Pipfile.lock"}

And after that DepHell will automatically detect your dependencies file:

$ dephell deps convert

You can still override this config for one-off actions:

$ dephell deps convert --to requirements.txt

See configuration documentation for more details.

More examples

You can convert anything to anything:

  1. Lock requirements.txt: dephell deps convert --to=requirements.txt
  2. Lock Pipfile: dephell deps convert --from=Pipfile --to=Pipfile.lock
  3. Lock poetry: dephell deps convert --from=pyproject.toml --to=poetry.lock
  4. Migrate from to poetry: dephell deps convert --to=pyproject.toml
  5. Migrate from pipenv to poetry: dephell deps convert --from=Pipfile --to=pyproject.toml
  6. Generate for poetry (to make project backward compatible with setuptools): dephell deps convert --from=pyproject.toml
  7. Generate requirements.txt from Pipfile to work on a pipenv-based project without pipenv: dephell deps convert --from=Pipfile --to=requirements.txt
  8. Generate requirements.txt from poetry to work on a poetry-based project without poetry: dephell deps convert --from=pyproject.toml --to=requirements.txt
  9. Pipe poetry requirements into pip for installation in a custom environment: pip install -r <(dephell deps convert --to-path stdout --to-format pip)

Filter dependencies

You can filter dependencies by envs with --envs flag. All dependencies included in main or dev env. Also, some dependencies can be included in extras. There is an example of poetry config with envs in comments:

python = ">=3.5"
aiohttp = "*"       # main, asyncio
textdistance = "*"  # main

pytest = "*"    # dev, tests
sphinx = "*"    # dev

asyncio = ["aiohttp"]
tests = ["pytest"]

Examples, how to filter these deps:

$ dephell deps convert --envs main
# aiohttp, textdistance

$ dephell deps convert --envs asyncio
# aiohttp

$ dephell deps convert --envs main tests
# aiohttp, textdistance, pytest

See also

  1. dephell project build to fast convert dependencies into, sdist and wheel.
  2. dephell deps install to install project dependencies.
  3. dephell deps tree to show dependencies tree for project.