0
# Routines
1
2
High-level operations that implement core pipenv functionality. These functions provide the main business logic for install, lock, sync, and other operations. Routines are the implementation layer called by CLI commands and can be used programmatically.
3
4
## Capabilities
5
6
### Package Installation
7
8
Install packages from PyPI, VCS, or local paths and manage Pipfile updates.
9
10
```python { .api }
11
def do_install(
12
project,
13
packages=False,
14
editable_packages=False,
15
index=False,
16
dev=False,
17
python=False,
18
pypi_mirror=None,
19
system=False,
20
ignore_pipfile=False,
21
requirementstxt=False,
22
pre=False,
23
deploy=False,
24
site_packages=None,
25
extra_pip_args=None,
26
pipfile_categories=None,
27
skip_lock=False,
28
):
29
"""
30
Install packages and add them to Pipfile, or install all from Pipfile.
31
32
Parameters:
33
- project: Project instance
34
- packages: List of package names to install
35
- editable_packages: List of editable packages to install
36
- dev: Install as development dependencies
37
- pre: Allow pre-release packages
38
- system: Use system pip instead of virtualenv
39
- ignore_pipfile: Ignore Pipfile and install from command line only
40
- skip_lock: Skip locking mechanism
41
- deploy: Abort if lockfile is out-of-date
42
"""
43
```
44
45
### Dependency Locking
46
47
Generate and manage Pipfile.lock with resolved dependencies.
48
49
```python { .api }
50
def do_lock(
51
project,
52
system=False,
53
clear=False,
54
pre=False,
55
write=True,
56
quiet=False,
57
pypi_mirror=None,
58
categories=None,
59
extra_pip_args=None,
60
):
61
"""
62
Generate Pipfile.lock with resolved dependencies.
63
64
Parameters:
65
- project: Project instance
66
- clear: Clear dependency resolver cache
67
- pre: Allow pre-release packages
68
- write: Write lockfile to disk
69
- categories: Specific package categories to lock
70
"""
71
```
72
73
### Package Synchronization
74
75
Install packages from Pipfile.lock to ensure deterministic builds.
76
77
```python { .api }
78
def do_sync(
79
project,
80
dev=False,
81
python=False,
82
bare=False,
83
dont_upgrade=False,
84
user=False,
85
clear=False,
86
unused=False,
87
system=False,
88
deploy=False,
89
pypi_mirror=None,
90
site_packages=None,
91
extra_pip_args=None,
92
categories=None,
93
):
94
"""
95
Install all packages specified in Pipfile.lock.
96
97
Parameters:
98
- project: Project instance
99
- dev: Include development dependencies
100
- bare: Minimal output
101
- dont_upgrade: Don't upgrade packages
102
- unused: Uninstall packages not in lockfile
103
- deploy: Abort if lockfile is out-of-date
104
"""
105
```
106
107
### Package Removal
108
109
Uninstall packages and remove from Pipfile.
110
111
```python { .api }
112
def do_uninstall(
113
project,
114
packages=False,
115
editable_packages=False,
116
all_dev=False,
117
all=False,
118
python=False,
119
system=False,
120
lock=False,
121
all_packages=False,
122
keep_outdated=False,
123
pypi_mirror=None,
124
ctx=None,
125
categories=None,
126
):
127
"""
128
Uninstall packages and remove from Pipfile.
129
130
Parameters:
131
- project: Project instance
132
- packages: List of package names to uninstall
133
- all_dev: Uninstall all development packages
134
- all: Uninstall all packages
135
- lock: Update lockfile after uninstall
136
"""
137
138
def do_purge(project, bare=False, downloads=False, allow_global=False):
139
"""
140
Remove the virtualenv and all cached dependencies.
141
142
Parameters:
143
- project: Project instance
144
- bare: Minimal output
145
- downloads: Remove cached downloads
146
- allow_global: Allow purging global packages
147
"""
148
```
149
150
### Shell Operations
151
152
Manage shell environments and run commands.
153
154
```python { .api }
155
def do_shell(project, python=False, fancy=False, shell_args=None, anyway=False):
156
"""
157
Spawn a shell within the virtualenv.
158
159
Parameters:
160
- project: Project instance
161
- python: Use specific Python version
162
- fancy: Use a fancy shell prompt
163
- shell_args: Additional shell arguments
164
- anyway: Create shell even if no virtualenv exists
165
"""
166
167
def do_run(project, command, args, python=False, pypi_mirror=None):
168
"""
169
Run a command in the virtualenv.
170
171
Parameters:
172
- project: Project instance
173
- command: Command to run
174
- args: Command arguments
175
- python: Use specific Python version
176
"""
177
```
178
179
### Dependency Analysis
180
181
Analyze project dependencies and generate reports.
182
183
```python { .api }
184
def do_graph(project, bare=False, json=False, json_tree=False, reverse=False):
185
"""
186
Show dependency graph.
187
188
Parameters:
189
- project: Project instance
190
- bare: Minimal output
191
- json: Output as JSON
192
- json_tree: Output as JSON tree
193
- reverse: Show reverse dependencies
194
"""
195
196
def do_outdated(project, pypi_mirror=None, pre=False, clear=False):
197
"""
198
Show outdated packages.
199
200
Parameters:
201
- project: Project instance
202
- pre: Include pre-release packages
203
- clear: Clear cache before checking
204
"""
205
```
206
207
### Security and Cleanup
208
209
Security scanning and project maintenance.
210
211
```python { .api }
212
def do_check(
213
project,
214
python=False,
215
system=False,
216
db=False,
217
ignore=None,
218
output="screen",
219
key=None,
220
quiet=False,
221
exit_code=True,
222
policy_file=None,
223
save_json=None,
224
audit_and_monitor=True,
225
safety_project=None,
226
):
227
"""
228
Check for security vulnerabilities and PEP 508 markers.
229
230
Parameters:
231
- project: Project instance
232
- db: Path to safety database
233
- ignore: Vulnerability IDs to ignore
234
- output: Output format ('screen', 'json', etc.)
235
- policy_file: Path to policy file
236
- safety_project: Safety project configuration
237
"""
238
239
def do_clean(
240
project,
241
bare=False,
242
python=False,
243
dry_run=False,
244
system=False,
245
categories=None,
246
):
247
"""
248
Uninstall all packages not specified in Pipfile.lock.
249
250
Parameters:
251
- project: Project instance
252
- bare: Minimal output
253
- dry_run: Show what would be uninstalled without doing it
254
- categories: Specific package categories to clean
255
"""
256
257
def do_clear(project):
258
"""
259
Clear pipenv caches.
260
261
Parameters:
262
- project: Project instance
263
"""
264
```
265
266
### Update Operations
267
268
Update packages and dependencies.
269
270
```python { .api }
271
def do_update(
272
project,
273
packages=False,
274
editable_packages=False,
275
index=False,
276
dev=False,
277
python=False,
278
pypi_mirror=None,
279
system=False,
280
lock=True,
281
site_packages=None,
282
extra_pip_args=None,
283
pipfile_categories=None,
284
bare=False,
285
dry_run=False,
286
outdated=False,
287
clear=False,
288
):
289
"""
290
Update specified packages or all packages.
291
292
Parameters:
293
- project: Project instance
294
- packages: List of specific packages to update
295
- dev: Include development packages
296
- lock: Generate lockfile after update
297
- dry_run: Show what would be updated without doing it
298
- outdated: Only update outdated packages
299
"""
300
```
301
302
## Import Usage
303
304
```python
305
from pipenv.routines.install import do_install
306
from pipenv.routines.lock import do_lock
307
from pipenv.routines.sync import do_sync
308
from pipenv.routines.uninstall import do_uninstall, do_purge
309
from pipenv.routines.shell import do_shell, do_run
310
from pipenv.routines.graph import do_graph
311
from pipenv.routines.outdated import do_outdated
312
from pipenv.routines.check import do_check
313
from pipenv.routines.clean import do_clean
314
from pipenv.routines.clear import do_clear
315
from pipenv.routines.update import do_update
316
317
# Example usage
318
from pipenv.project import Project
319
320
project = Project()
321
do_install(project, packages=["requests"], dev=False)
322
do_lock(project)
323
```