Micropipenv
A lightweight wrapper for pip to support requirements.txt, Pipenv and Poetry lock files or converting them to pip-tools compatible output. Designed for containerized Python applications but not limited to them.
Install / Use
/learn @thoth-station/MicropipenvREADME
µPipenv
.. image:: https://img.shields.io/github/v/tag/thoth-station/micropipenv?style=plastic :target: https://github.com/thoth-station/micropipenv/releases :alt: GitHub tag (latest by date)
.. image:: https://travis-ci.com/thoth-station/micropipenv.svg?branch=master :target: https://travis-ci.com/thoth-station/micropipenv
.. image:: https://img.shields.io/pypi/pyversions/micropipenv?style=plastic :target: https://pypi.org/project/micropipenv :alt: PyPI - Python Version
.. image:: https://img.shields.io/pypi/l/micropipenv?style=plastic :target: https://pypi.org/project/micropipenv :alt: PyPI - License
.. image:: https://img.shields.io/pypi/dm/micropipenv?style=plastic :target: https://pypi.org/project/micropipenv :alt: PyPI - Downloads
A lightweight wrapper for pip to support requirements.txt, Pipenv and Poetry
lock files or converting them to pip-tools <https://pypi.org/project/pip-tools/>_ compatible output. Designed for
containerized Python applications but not limited to them.
For a brief video preview, check this demo <https://www.youtube.com/watch?v=I-QC83BcLuo&t=8m58s>_ (the micropipenv
part starts at 9:00).
See also micropipenv: Installing Python dependencies in containerized applications <https://developers.redhat.com/articles/2021/05/19/micropipenv-installing-python-dependencies-containerized-applications>__
for more info about this tool and a blog post published about it <https://dev.to/fridex/micropipenv-the-one-installation-tool-that-covers-pipenv-poetry-and-pip-tools-3ee7>__.
What's the difference in comparision to pip when using requirements.txt?
-
if
requirements.txtstate all the packages in a pinned version with hashes (e.g.pip-tools <https://pypi.org/project/pip-tools/>_), micropipenv installs packages with a possible fallback if the installation order is relevant-
you don't need to care about the installation and maintain correct order or requirements in
requirements.txt -
best effort installation - try until there is a possibility to succeed
-
-
if
requirements.txtdo not state all the packages in a pinned form-
pip's resolver algorithm is used and it's left on pip to resolve requirements
-
the same behavior as micropipenv would not be used
-
What's the difference in comparision to Poetry?
-
a lightweight addition to Poetry, not a Poetry replacement
- micropipenv does not substitute Poetry it rather complements it for containerized deployments where the size of the container image and software shipped with it matters
-
no release management to Python package indexes
-
micropipenv does not implement resolver, it uses already resolved stack that application is shipped with based on
poetry.lockandpyproject.toml -
no virtual environment management
- virtual environment management is left on user, if needed
What's the difference in comparision to Pipenv?
-
a lightweight addition to Pipenv, not a Pipenv replacement
- micropipenv does not substitute Pipenv it rather complements it for containerized deployments where the size of the container image and software shipped with it matters
-
it does not
vendor all the dependencies as Pipenv <https://github.com/pypa/pipenv/tree/master/pipenv/vendor>_ -
micropipenv does not implement resolver, it uses already resolved stack that application is shipped with
Pipfile.lock -
no virtual environment management
- virtual environment management is left on user, if needed
micropipenv use cases
Why should I use micropipenv instead of Pipenv <https://github.com/pypa/pipenv>_
or Poetry <https://pypi.org/project/poetry>_?
-
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 and
Pipenv upstream did not issue any new Pipenv release <https://github.com/pypa/pipenv/issues/4058>_. -
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 install
The tool supports installing dependencies of the following formats:
Pipenvstyle lock format - filesPipfileandPipfile.lockPoetrystyle lock format - filespyproject.tomlandpoetry.lockpip-toolsstyle lock format - filerequirements.txt- raw
requirements.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 --method option to the
install subcommand. By default, micropipenv traverses 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 rawpiprequirements
To install dependencies issue the following command:
.. code-block:: console
micropipenv install --dev # --dev is optional
You can supply additional positional arguments that will be passed to pip.
Use double dashes to distinguish pip options from micropipenv options.
.. code-block::
issue `pip install --user'
micropipenv install -- --user
Virtual environment management
micropipenv does not create any virtual environment as in the case of
Pipenv/Poetry. It simply executes pip, and constructs arguments out of the
lock file used. pip's default behaviour is to install its arguments into
the same Python environment where pip is installed (i.e., the system Python
environment).
To rather install its arguments into a virtual environment, run micropipenv
from a shell where that virtual environment has been activated. This causes
micropipenv to run the pip command already installed in the virtual
environment:
.. code-block:: console
python3 -m venv venv/ && (. venv/bin/activate && micropipenv install)
Alternatively, micropipenv can run the pip command from the system
Python environment, which can in turn be told to install its arguments into an
explicitly specified virtual environment by using the PIP_PYTHON
environment variable.
This allows for the installation of dependencies into a minimal virtual
environment that does not itself have pip and its dependencies installed
into it:
.. code-block:: console
python3 -m venv venv/ --without-pip && PIP_PYTHON=venv/bin/python micropipenv install
Using another package index
To set the default Python Package Index to something other than https://pypi.org/simple, set the MICROPIPENV_DEFAULT_INDEX_URLS to one or more comma-separated URLs.
Note: if the package manager file contains a package index URL, it will be used over this value.
.. code-block:: console
export MICROPIPENV_DEFAULT_INDEX_URLS=https://pypi.example.com/simple,https://pypi.org/simple micropipenv install
micropipenv install --deploy
If you wish to mimic pipenv --deploy functionality, you can do so:
.. code-block:: console
micropipenv install --deploy
Note however, there is a need to parse Pipfile and verify its content
corresponds to Pipefile.lock used (digest computed on Pipfile content).
micropipenv requires toml extras for this functionality, so you will need
to install micropipenv[toml] (see installation instructions bellow).
The --deploy option takes no effect for Poetry and requirements
installation methods.
micropipenv install --dev
Installation of "development" dependencies can be acomplished using the
--dev flag. This flag has no effect when requirements.txt file is used.
micropipenv requirements / micropipenv req
To generate output compatible with pip-tools <https://pypi.org/project/pip-tools/>_, you can issue the following command:
.. code-block:: console
micropipenv requirements
This applies to conversion from Poetry and Pipenv specific lock files.
Additional configuration options can limit what is present in the output (e.g.
--no-dev to remove development dependencies).
A special option --only-direct makes micropipenv work on Pipfile
instead of Pipfile.lock. This requires toml extras, so install
micropipenv[toml] for this functionality (see installation instructions
bellow). To get direct dependencies of an application and store them in
requirements.txt file:
.. code-block:: console
micropipenv requirements --only-direct > requirements.txt
For a setup that follows pip-tools conven
