Package: micropipenv
A lightweight wrapper for pip to support requirements.txt, Pipenv and Poetry
lock files or converting them topip-toolscompatible output. Designed for
containerized Python applications but not limited to them.For a brief video preview,check this demo(the micropipenv
part starts at 9:00).See alsomicropipenv: Installing Python dependencies in containerized
applicationsfor more info about this tool and ablog post published about it.What’s the difference in comparision to pip when using requirements.txt?ifrequirements.txtstate all the packages in a pinned version with
hashes (e.g.pip-tools), micropipenv
installs packages with a possible fallback if the installation order is
relevantyou don’t need to care about the installation and maintain correct order or
requirements inrequirements.txtbest effort installation - try until there is a possibility to succeedifrequirements.txtdo not state all the packages in a pinned formpip’s resolver algorithm is used and it’s left on pip to resolve
requirementsthe same behavior as micropipenv would not be usedWhat’s the difference in comparision to Poetry?a lightweight addition to Poetry, not a Poetry replacementmicropipenv does not substitute Poetry it rather complements it for
containerized deployments where the size of the container image and
software shipped with it mattersno release management to Python package indexesmicropipenv does not implement resolver, it uses already resolved stack that
application is shipped with based onpoetry.lockandpyproject.tomlno virtual environment managementvirtual environment management is left on user, if neededWhat’s the difference in comparision to Pipenv?a lightweight addition to Pipenv, not a Pipenv replacementmicropipenv does not substitute Pipenv it rather complements it for
containerized deployments where the size of the container image and
software shipped with it mattersit does notvendor all the dependencies as Pipenvmicropipenv does not implement resolver, it uses already resolved stack that
application is shipped withPipfile.lockno virtual environment managementvirtual environment management is left on user, if neededmicropipenv use casesWhy should I usemicropipenvinstead ofPipenvorPoetry?I would like to have a tool that “rules them all” - one lightweight tool to
support all Python dependency lock file managers (pip-tools, Poetry, Pipenv)
and lets users decide what they want to use when deploying Python applications
in containerized environments (e.g. Kubernetes, OpenShift, …).I would like to have a fast and minimalistic tool to install software
packages in CI.I would like to have containerized Python applications as small as possible
with minimum software shipped and required to build and run the Python
application in production.I would like to convert files produced by Pipenv/Poetry to a pip-tools
compatible output.I don’t want to install Pipenv/Poetry, but I would like to run a project that
uses Pipenv/Poetry for dependency management (e.g. restricted environments).My Pipenv installation is broken andPipenv upstream did not issue any new
Pipenv release.I would like to deploy my application into a production environment and my
application dependencies are managed by Pipenv/Poetry (dependencies are
already resolved), but I don’t want to run Pipenv/Poetry in production (e.g.
OpenShift’s s2i build process).micropipenv installThe tool supports installing dependencies of the following formats:Pipenvstyle lock format - filesPipfileandPipfile.lockPoetrystyle lock format - filespyproject.tomlandpoetry.lockpip-toolsstyle lock format - filerequirements.txtrawrequirements.txtas used bypip(not a lock file)In case of Pipenv, Poetry and pip-tools style format, the tool performs
automatic recovery if the installation order of dependencies is relevant (one
dependency fails to install as it depends on an another one).To enforce the installation method used, specify--methodoption to theinstallsubcommand. By default,micropipenvtraverses the filesystem up
from the current working directory and looks for the relevant files in the
following order:Pipfile.lockand optionallyPipfile(if--deployset)poetry.lockandpyproject.tomlrequirements.txtforpip-toolsand rawpiprequirementsTo install dependencies issue the following command:micropipenv install --dev  # --dev is optionalYou can supply additional positional arguments that will be passed topip.
Use double dashes to distinguishpipoptions frommicropipenvoptions.# issue `pip install --user'
micropipenv install -- --usermicropipenvdoes not create any virtual environment as in case of
Pipenv/Poetry.  It rather directly talks topip, if necessary, and
constructs arguments out of the lock file used.To create a virtual environment to be used bymicropipenv:python3 -m venv venv/ && . venv/bin/activateTo set the default Python Package Index to something other thanhttps://pypi.org/simple, set theMICROPIPENV_DEFAULT_INDEX_URLSto one or more comma-separated URLs.Note: if the package manager file contains a package index URL, it will be used over this value.export MICROPIPENV_DEFAULT_INDEX_URLS=https://pypi.example.com/simple,https://pypi.org/simple
micropipenv installmicropipenv install--deployIf you wish to mimicpipenv--deployfunctionality, you can do so:micropipenv install --deployNote however, there is a need to parsePipfileand verify its content
corresponds to Pipefile.lock used (digest computed onPipfilecontent).micropipenvrequires toml extras for this functionality, so you will need
to installmicropipenv[toml](see installation instructions bellow).The--deployoption takes no effect for Poetry and requirements
installation methods.micropipenv install--devInstallation of “development” dependencies can be acomplished using the--devflag. This flag has no effect whenrequirements.txtfile is used.micropipenv requirements/micropipenv reqTo generate output compatible withpip-tools, you can issue the following command:micropipenv requirementsThis applies to conversion from Poetry and Pipenv specific lock files.Additional configuration options can limit what is present in the output (e.g.--no-devto remove development dependencies).A special option--only-directmakesmicropipenvwork onPipfileinstead ofPipfile.lock. This requires toml extras, so installmicropipenv[toml]for this functionality (see installation instructions
bellow). To get direct dependencies of an application and store them in
requirements.txt file:micropipenv requirements --only-direct > requirements.txtFor a setup that followspip-toolsconvention withrequirements.inandrequirements.txtmicropipenv requirements --no-dev > requirements.txt
micropipenv requirements --no-dev --only-direct > requirements.in
micropipenv requirements --no-default > dev-requirements.txt
micropipenv requirements --no-default --only-direct > dev-requirements.inSeemicropipenv requirements--helpfor more info.micropipenvas a librarymicropipenvexposes some core functionality on top ofPipfile/Pipfile.lock.  You can import its functions and usemicropipenvas a lightweight library forPipfile/Pipfile.lockandpyproject.toml/poetry.lockmanipulation.Adjusting options using environment variablesAll options can be triggered using environment variables - the name of an
environment variable is always prefixed withMICROPIPENV_and consists of
the name of the option converted to uppercase, dashes are replaced with
underscores (example--no-devis mapped toMICROPIPENV_NO_DEV). All
environment variables corresponding to flags are parsed as integers and
subsequently casted to a boolean. For example, to turn--no-devflag on,
setMICROPIPENV_NO_DEV=1(0 disables the flag). Parameters supplied to CLI
take precedence over environment variables.A special environment variableMICROPIPENV_PIP_BINcan point to an
alternatepipbinary.To run this tool in a verbose mode, you can set theMICROPIPENV_DEBUG=1(the
same behavior can be achieved with multiple--verbosesupplied).The tool prints software stack information to the standard error output. This was
designed for Thoth to capture information about installed dependencies as a
useful source of information for Thoth’s build analyzers. This behaviour can be
suppressed by settingMICROPIPENV_NO_LOCKFILE_PRINT=1environment variable.Besides printing, the tool also writes the content of Pipfile.lock (if a locked
software stack is used) to the directory where lock files are present (for Pipenv
files, the Pipfile.lock is kept untouched). This behaviour can be suppressed by
providingMICROPIPENV_NO_LOCKFILE_WRITE=1environment variable.Example usageInstall dependencies managed by Poetry aspip install--userwould do
(option--methodis optional, auto-discovery is performed if omitted):$lspoetry.lock pyproject.toml project.py$micropipenvinstall--methodpoetry----userInstall dependencies (both main and develop) managed by Poetry into a virtual
environment:$lspoetry.lock pyproject.toml project.py$python3-mvenvvenv/$.venv/bin/activate(venv)$micropipenvinstall--devInstall dependencies managed by Pipenv (both main and develop) into a virtual
environment  (option--methodis optional, auto-discovery is performed if
omitted):$lsPipfile Pipfile.lock src/$python3-mvenvvenv/$.venv/bin/activate(venv)$micropipenvinstall--devPerform deployment of an application as Pipenv would do with Python interpreter
version check and Pipfile file hash check (you can create virtual environment
only if necessary):$lsPipfile Pipfile.lock src/$python3-mvenvvenv/$.venv/bin/activate(venv)$micropipenvinstall--deployGeneratepip-toolscompliantrequirements.in,dev-requirements.in,requirements.txtanddev-requirements.txtout ofPipfileandPipfile.lock- project
dependencies managed by Pipenv:$lsPipfile Pipfile.lock src/$micropipenvrequirements--no-dev>requirements.txt$micropipenvrequirements--no-dev--only-direct>requirements.in$micropipenvrequirements--no-default>dev-requirements.txt$micropipenvrequirements--no-default--only-direct>dev-requirements.inGeneratepip-toolscomplaintrequirements.in,dev-requirements.in,requirements.txtanddev-requirements.txtout ofpyproject.tomlandpoetry.lock- project
dependencies managed by Poetry:$lspoetry.lock pyproject.toml src/$micropipenvrequirements--no-dev>requirements.txt$micropipenvrequirements--no-dev--only-direct>requirements.in$micropipenvrequirements--no-default>dev-requirements.txt$micropipenvrequirements--no-default--only-direct>dev-requirements.inFor OpenShift’s s2i integration,check this repo with a demo.InstallationThe project ishosted on PyPIso
installing it usingpipworks as expected:pip install micropipenvThe default installation does not bring any dependencies so its justmicropipenvthat gets installed. However, the default installation supports
onlyPipfile.lockmanagement. If you would like to manipulate also withPipfileor Poetry specific lock files, you will need to installmicropipenvwith TOML support (TOML is not in the standard Python library):pip install micropipenv[toml]Once the project gets installed, you can browse the help message by invoking
themicropipenvCLI:micropipenv --helpIf you wish to installmicropipenvon your Fedora system:dnf install -y micropipenvSee availableRPM packages.No installationYou can runmicropipenvwithout actually installing it - simply download
the file and execute it. If you do not wish to savemicropipenv.pyfile to
disk, you can issue:curl https://raw.githubusercontent.com/thoth-station/micropipenv/master/micropipenv.py | python3 - --helpAnything afterpython3 -will be passed as an argument tomicropipenv.pyso installing packages can be simply performed using:curl https://raw.githubusercontent.com/thoth-station/micropipenv/master/micropipenv.py | python3 - install -- --userAll arguments after – will be passed topipas options.OpenShift s2i (Source-To-Image)micropipenv is available in UBI, Fedora and RHEL based container images. To
enable micropipenv and benefit from its features, you need to exportENABLE_MICROPIPENV=1environment variable in more recent Python 3 container
images. Seesclorg/s2i-python-containerrepo for
more information.License and copyingThis project is licensed under the terms of the GNU Lesser General Public
License v3 or later. SeeLICENSE-LGPLandLICENSE-GPLfiles for the
license terms.Copyright (C) 2020-2022Project Thoth; Red Hat Inc.Original author:Fridolín ‘fridex’ Pokorný <fridolin@redhat.com>Maintainers:Lumír ‘Frenzy’ Balhar <lbalhar@redhat.com>Max Gautier <max.gautier@redhat.com>