• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H27-Feb-2020-8861

examples/H27-Feb-2020-1611

img/H03-May-2022-

pip_tools.egg-info/H03-May-2022-393296

piptools/H27-Feb-2020-3,0142,320

tests/H27-Feb-2020-3,7082,903

.appveyor.ymlH A D27-Feb-20204 KiB160147

.banditH A D27-Feb-202046 32

.coveragercH A D27-Feb-2020101 97

.fussyfox.ymlH A D27-Feb-202026 43

.gitignoreH A D27-Feb-2020259 3225

.pre-commit-config.yamlH A D27-Feb-2020508 2322

.travis.ymlH A D27-Feb-20202.4 KiB10795

CHANGELOG.mdH A D27-Feb-202021 KiB496354

CONTRIBUTING.mdH A D27-Feb-20203 KiB4938

LICENSEH A D27-Feb-20201.5 KiB2721

PKG-INFOH A D27-Feb-202016.4 KiB393296

README.rstH A D27-Feb-202012.4 KiB365269

setup.cfgH A D27-Feb-2020719 3326

setup.pyH A D27-Feb-20201.9 KiB5751

tox.iniH A D27-Feb-20201.7 KiB7367

README.rst

1|jazzband| |pypi| |pyversions| |buildstatus-travis| |buildstatus-appveyor| |codecov|
2
3==================================
4pip-tools = pip-compile + pip-sync
5==================================
6
7A set of command line tools to help you keep your ``pip``-based packages fresh,
8even when you've pinned them.  You do pin them, right? (In building your Python application and its dependencies for production, you want to make sure that your builds are predictable and deterministic.)
9
10.. image:: https://github.com/jazzband/pip-tools/raw/master/img/pip-tools-overview.png
11   :alt: pip-tools overview for phase II
12
13.. |buildstatus-travis| image:: https://img.shields.io/travis/jazzband/pip-tools/master.svg?logo=travis
14   :alt: Travis CI build status
15   :target: https://travis-ci.org/jazzband/pip-tools
16.. |buildstatus-appveyor| image:: https://img.shields.io/appveyor/ci/jazzband/pip-tools/master.svg?logo=appveyor
17   :alt: AppVeyor build status
18   :target: https://ci.appveyor.com/project/jazzband/pip-tools
19.. |codecov| image:: https://codecov.io/gh/jazzband/pip-tools/branch/master/graph/badge.svg
20   :alt: Coverage
21   :target: https://codecov.io/gh/jazzband/pip-tools
22.. |jazzband| image:: https://jazzband.co/static/img/badge.svg
23   :alt: Jazzband
24   :target: https://jazzband.co/
25.. |pypi| image:: https://img.shields.io/pypi/v/pip-tools.svg
26   :alt: PyPI version
27   :target: https://pypi.org/project/pip-tools/
28.. |pyversions| image:: https://img.shields.io/pypi/pyversions/pip-tools.svg
29   :alt: Supported Python versions
30   :target: https://pypi.org/project/pip-tools/
31.. _You do pin them, right?: http://nvie.com/posts/pin-your-packages/
32
33
34Installation
35============
36
37Similar to ``pip``, ``pip-tools`` must be installed in each of your project's
38`virtual environments`_:
39
40.. code-block:: bash
41
42    $ source /path/to/venv/bin/activate
43    (venv)$ pip install pip-tools
44
45**Note**: all of the remaining example commands assume you've activated your
46project's virtual environment.
47
48.. _virtual environments: https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments
49
50Example usage for ``pip-compile``
51=================================
52
53The ``pip-compile`` command lets you compile a ``requirements.txt`` file from
54your dependencies, specified in either ``setup.py`` or ``requirements.in``.
55
56Run it with ``pip-compile`` or  ``python -m piptools compile``. If you use
57multiple Python versions, you can run ``pip-compile`` as ``py -X.Y -m piptools
58compile`` on Windows and ``pythonX.Y -m piptools compile`` on other systems.
59
60``pip-compile`` should be run from the same virtual environment as your
61project so conditional dependencies that require a specific Python version,
62or other environment markers, resolve relative to your project's
63environment.
64
65**Note**: ensure you don't have ``requirements.txt`` if you compile
66``setup.py`` or ``requirements.in`` from scratch, otherwise, it might
67interfere.
68
69Requirements from ``setup.py``
70------------------------------
71
72Suppose you have a Django project, and want to pin it for production.
73If you have a ``setup.py`` with ``install_requires=['django']``, then run
74``pip-compile`` without any arguments:
75
76.. code-block:: bash
77
78    $ pip-compile
79    #
80    # This file is autogenerated by pip-compile
81    # To update, run:
82    #
83    #    pip-compile
84    #
85    asgiref==3.2.3            # via django
86    django==3.0.3             # via my_django_project (setup.py)
87    pytz==2019.3              # via django
88    sqlparse==0.3.0           # via django
89
90``pip-compile`` will produce your ``requirements.txt``, with all the Django
91dependencies (and all underlying dependencies) pinned.  You should put
92``requirements.txt`` under version control.
93
94Without ``setup.py``
95--------------------
96
97If you don't use ``setup.py`` (`it's easy to write one`_), you can create a
98``requirements.in`` file to declare the Django dependency:
99
100.. code-block:: ini
101
102    # requirements.in
103    django
104
105Now, run ``pip-compile requirements.in``:
106
107.. code-block:: bash
108
109    $ pip-compile requirements.in
110    #
111    # This file is autogenerated by pip-compile
112    # To update, run:
113    #
114    #    pip-compile requirements.in
115    #
116    asgiref==3.2.3            # via django
117    django==3.0.3             # via -r requirements.in
118    pytz==2019.3              # via django
119    sqlparse==0.3.0           # via django
120
121And it will produce your ``requirements.txt``, with all the Django dependencies
122(and all underlying dependencies) pinned.  You should put both
123``requirements.in`` and ``requirements.txt`` under version control.
124
125.. _it's easy to write one: https://packaging.python.org/guides/distributing-packages-using-setuptools/#configuring-your-project
126
127Using hashes
128------------
129
130If you would like to use *Hash-Checking Mode* available in ``pip`` since
131version 8.0, ``pip-compile`` offers ``--generate-hashes`` flag:
132
133.. code-block:: bash
134
135    $ pip-compile --generate-hashes requirements.in
136    #
137    # This file is autogenerated by pip-compile
138    # To update, run:
139    #
140    #    pip-compile --generate-hashes requirements.in
141    #
142    asgiref==3.2.3 \
143        --hash=sha256:7e06d934a7718bf3975acbf87780ba678957b87c7adc056f13b6215d610695a0 \
144        --hash=sha256:ea448f92fc35a0ef4b1508f53a04c4670255a3f33d22a81c8fc9c872036adbe5 \
145        # via django
146    django==3.0.3 \
147        --hash=sha256:2f1ba1db8648484dd5c238fb62504777b7ad090c81c5f1fd8d5eb5ec21b5f283 \
148        --hash=sha256:c91c91a7ad6ef67a874a4f76f58ba534f9208412692a840e1d125eb5c279cb0a \
149        # via -r requirements.in
150    pytz==2019.3 \
151        --hash=sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d \
152        --hash=sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be \
153        # via django
154    sqlparse==0.3.0 \
155        --hash=sha256:40afe6b8d4b1117e7dff5504d7a8ce07d9a1b15aeeade8a2d10f130a834f8177 \
156        --hash=sha256:7c3dca29c022744e95b547e867cee89f4fce4373f3549ccd8797d8eb52cdb873 \
157        # via django
158
159Updating requirements
160---------------------
161
162To update all packages, periodically re-run ``pip-compile --upgrade``.
163
164To update a specific package to the latest or a specific version use the
165``--upgrade-package`` or ``-P`` flag:
166
167.. code-block:: bash
168
169    # only update the django package
170    $ pip-compile --upgrade-package django
171
172    # update both the django and requests packages
173    $ pip-compile --upgrade-package django --upgrade-package requests
174
175    # update the django package to the latest, and requests to v2.0.0
176    $ pip-compile --upgrade-package django --upgrade-package requests==2.0.0
177
178You can combine ``--upgrade`` and ``--upgrade-package`` in one command, to
179provide constraints on the allowed upgrades. For example to upgrade all
180packages whilst constraining requests to the latest version less than 3.0:
181
182.. code-block:: bash
183
184    $ pip-compile --upgrade --upgrade-package 'requests<3.0'
185
186Output File
187-----------
188
189To output the pinned requirements in a filename other than
190``requirements.txt``, use ``--output-file``. This might be useful for compiling
191multiple files, for example with different constraints on django to test a
192library with both versions using `tox <https://tox.readthedocs.io/en/latest/>`__:
193
194.. code-block:: bash
195
196    $ pip-compile --upgrade-package 'django<1.0' --output-file requirements-django0x.txt
197    $ pip-compile --upgrade-package 'django<2.0' --output-file requirements-django1x.txt
198
199Or to output to standard output, use ``--output-file=-``:
200
201.. code-block:: bash
202
203    $ pip-compile --output-file=- > requirements.txt
204    $ pip-compile - --output-file=- < requirements.in > requirements.txt
205
206Configuration
207-------------
208
209You might be wrapping the ``pip-compile`` command in another script. To avoid
210confusing consumers of your custom script you can override the update command
211generated at the top of requirements files by setting the
212``CUSTOM_COMPILE_COMMAND`` environment variable.
213
214.. code-block:: bash
215
216    $ CUSTOM_COMPILE_COMMAND="./pipcompilewrapper" pip-compile requirements.in
217    #
218    # This file is autogenerated by pip-compile
219    # To update, run:
220    #
221    #    ./pipcompilewrapper
222    #
223    asgiref==3.2.3            # via django
224    django==3.0.3             # via -r requirements.in
225    pytz==2019.3              # via django
226    sqlparse==0.3.0           # via django
227
228Workflow for layered requirements
229---------------------------------
230
231If you have different environments that you need to install different but
232compatible packages for, then you can create layered requirements files and use
233one layer to constrain the other.
234
235For example, if you have a Django project where you want the newest ``2.1``
236release in production and when developing you want to use the Django debug
237toolbar, then you can create two ``*.in`` files, one for each layer:
238
239.. code-block:: ini
240
241    # requirements.in
242    django<2.2
243
244At the top of the development requirements ``dev-requirements.in`` you use ``-c
245requirements.txt`` to constrain the dev requirements to packages already
246selected for production in ``requirements.txt``.
247
248.. code-block:: ini
249
250    # dev-requirements.in
251    -c requirements.txt
252    django-debug-toolbar
253
254First, compile ``requirements.txt`` as usual:
255
256.. code-block:: bash
257
258    $ pip-compile
259    #
260    # This file is autogenerated by pip-compile
261    # To update, run:
262    #
263    #    pip-compile
264    #
265    django==2.1.15            # via -r requirements.in
266    pytz==2019.3              # via django
267
268
269Now compile the dev requirements and the ``requirements.txt`` file is used as
270a constraint:
271
272.. code-block:: bash
273
274    $ pip-compile dev-requirements.in
275    #
276    # This file is autogenerated by pip-compile
277    # To update, run:
278    #
279    #    pip-compile dev-requirements.in
280    #
281    django-debug-toolbar==2.2  # via -r dev-requirements.in
282    django==2.1.15            # via -c requirements.txt, django-debug-toolbar
283    pytz==2019.3              # via -c requirements.txt, django
284    sqlparse==0.3.0           # via django-debug-toolbar
285
286As you can see above, even though a ``2.2`` release of Django is available, the
287dev requirements only include a ``2.1`` version of Django because they were
288constrained. Now both compiled requirements files can be installed safely in
289the dev environment.
290
291To install requirements in production stage use:
292
293.. code-block:: bash
294
295    $ pip-sync
296
297You can install requirements in development stage by:
298
299.. code-block:: bash
300
301    $ pip-sync requirements.txt dev-requirements.txt
302
303
304Example usage for ``pip-sync``
305==============================
306
307Now that you have a ``requirements.txt``, you can use ``pip-sync`` to update
308your virtual environment to reflect exactly what's in there. This will
309install/upgrade/uninstall everything necessary to match the
310``requirements.txt`` contents.
311
312Run it with ``pip-sync`` or ``python -m piptools sync``. If you use multiple
313Python versions, you can also run ``py -X.Y -m piptools sync`` on Windows and
314``pythonX.Y -m piptools sync`` on other systems.
315
316``pip-sync`` must be installed into and run from the same virtual
317environment as your project to identify which packages to install
318or upgrade.
319
320**Be careful**: ``pip-sync`` is meant to be used only with a
321``requirements.txt`` generated by ``pip-compile``.
322
323.. code-block:: bash
324
325    $ pip-sync
326    Uninstalling flake8-2.4.1:
327      Successfully uninstalled flake8-2.4.1
328    Collecting click==4.1
329      Downloading click-4.1-py2.py3-none-any.whl (62kB)
330        100% |................................| 65kB 1.8MB/s
331      Found existing installation: click 4.0
332        Uninstalling click-4.0:
333          Successfully uninstalled click-4.0
334    Successfully installed click-4.1
335
336To sync multiple ``*.txt`` dependency lists, just pass them in via command
337line arguments, e.g.
338
339.. code-block:: bash
340
341    $ pip-sync dev-requirements.txt requirements.txt
342
343Passing in empty arguments would cause it to default to ``requirements.txt``.
344
345If you use multiple Python versions, you can run ``pip-sync`` as
346``py -X.Y -m piptools sync ...`` on Windows and
347``pythonX.Y -m piptools sync ...`` on other systems.
348
349**Note**: ``pip-sync`` will not upgrade or uninstall packaging tools like
350``setuptools``, ``pip``, or ``pip-tools`` itself. Use ``pip install --upgrade``
351to upgrade those packages.
352
353Other useful tools
354==================
355
356- `pipdeptree`_ to print the dependency tree of the installed packages.
357- ``requirements.in``/``requirements.txt`` syntax highlighting:
358
359  * `requirements.txt.vim`_ for Vim.
360  * `Python extension for VS Code`_ for VS Code.
361
362.. _pipdeptree: https://github.com/naiquevin/pipdeptree
363.. _requirements.txt.vim: https://github.com/raimon49/requirements.txt.vim
364.. _Python extension for VS Code: https://marketplace.visualstudio.com/items?itemName=ms-python.python
365