Python Development Workflow for Humans.
—
Complete CLI with 15 commands for managing Python projects including installation, environment management, dependency resolution, and project operations. The CLI is built using Click and provides both individual commands and a main group with global options.
The main CLI entry point with global options that apply to all subcommands.
def cli():
"""
Main CLI group with global options.
Global Options:
--where: Output project home information
--venv: Output virtualenv information
--py: Output Python interpreter information
--envs: Output environment variable options
--rm: Remove the virtualenv
--bare: Minimal output
--man: Display manpage
--support: Output diagnostic information
--version: Show version information
--verbose: Verbose output
--quiet: Quiet output
--clear: Clear caches
--python: Specify Python version
"""Install packages from PyPI, VCS, or local paths and automatically add them to Pipfile.
def install(*packages, dev=False, pre=False, editable=False, system=False,
ignore_pipfile=False, skip_lock=False, requirements=None, **kwargs):
"""
Install packages and add to Pipfile, or install all from Pipfile.
Parameters:
packages: Package names to install
dev: Install as development dependency
pre: Allow pre-release packages
editable: Install package in editable mode
system: Use system pip instead of virtualenv
ignore_pipfile: Ignore Pipfile and install from command line only
skip_lock: Skip locking mechanism
requirements: Install from requirements.txt file
"""Usage examples:
pipenv install requests # Install and add to Pipfile
pipenv install pytest --dev # Install as dev dependency
pipenv install -e git+https://... # Install from git in editable mode
pipenv install --requirements requirements.txt # Install from requirements.txt
pipenv install # Install all from PipfileRemove packages from the virtual environment and Pipfile.
def uninstall(*packages, all_dev=False, all=False, dev=False):
"""
Remove packages from virtualenv and Pipfile.
Parameters:
packages: Package names to uninstall
all_dev: Remove all development packages
all: Remove all packages
dev: Remove from development dependencies
"""Usage examples:
pipenv uninstall requests # Remove specific package
pipenv uninstall --all-dev # Remove all dev packages
pipenv uninstall --all # Remove all packagesUpdate packages to newer versions and regenerate lock file.
def update(*packages, dev=False, bare=False, outdated=False, dry_run=False):
"""
Run lock, then sync (or upgrade specific packages).
Parameters:
packages: Specific packages to update
dev: Include development packages
bare: Minimal output
outdated: Show outdated packages
dry_run: Show what would be updated without making changes
"""
def upgrade(*packages, dev=False, pre=False, lock_only=False):
"""
Resolve and upgrade packages, merge results to Pipfile.lock.
Parameters:
packages: Specific packages to upgrade
dev: Include development packages
pre: Allow pre-release packages
lock_only: Only update lock file, don't install
"""Usage examples:
pipenv update # Update all packages
pipenv update requests # Update specific package
pipenv update --outdated # Show outdated packages
pipenv upgrade # Upgrade packages and lockGenerate and manage Pipfile.lock for deterministic builds.
def lock(dev=False, dev_only=False, pre=False, categories=None):
"""
Generate Pipfile.lock.
Parameters:
dev: Include development dependencies
dev_only: Only include development dependencies
pre: Allow pre-release packages
categories: Specific categories to lock
"""Usage examples:
pipenv lock # Generate lock file
pipenv lock --dev # Include dev dependencies
pipenv lock --dev-only # Only dev dependenciesInstall packages exactly as specified in Pipfile.lock.
def sync(bare=False, dev=False, system=False):
"""
Install packages from Pipfile.lock.
Parameters:
bare: Minimal output
dev: Include development packages
system: Use system pip
"""Usage examples:
pipenv sync # Install from lock file
pipenv sync --dev # Include dev packagesSpawn a shell within the virtual environment.
def shell(fancy=False, anyway=False, quiet=False, *args):
"""
Spawn shell within virtualenv.
Parameters:
fancy: Use fancy shell prompt
anyway: Always spawn shell even if already active
quiet: Quiet output
args: Additional shell arguments
"""Usage examples:
pipenv shell # Activate environment shell
pipenv shell --fancy # Use fancy promptExecute commands within the virtual environment.
def run(*command):
"""
Execute command in virtualenv.
Parameters:
command: Command name and arguments to execute
"""Usage examples:
pipenv run python script.py # Run Python script
pipenv run pytest # Run tests
pipenv run python -m module # Run moduleDisplay dependency graph and analyze package relationships.
def graph(bare=False, json=False, json_tree=False, reverse=False):
"""
Display dependency graph information.
Parameters:
bare: Minimal output
json: Output in JSON format
json_tree: Output JSON dependency tree
reverse: Show reverse dependencies
"""Usage examples:
pipenv graph # Show dependency graph
pipenv graph --json # JSON output
pipenv graph --reverse # Show reverse dependenciesRemove packages not specified in Pipfile.lock.
def clean(bare=False, dry_run=False):
"""
Remove packages not in Pipfile.lock.
Parameters:
bare: Minimal output
dry_run: Show what would be removed without making changes
"""Usage examples:
pipenv clean # Remove extra packages
pipenv clean --dry-run # Show what would be removedCheck for security vulnerabilities in installed packages (deprecated).
def check(db=None, ignore=None, output="screen", key=None, scan=False, auto_install=False):
"""
Security vulnerability checks via PyUp Safety (DEPRECATED).
Parameters:
db: Path to safety database
ignore: Ignore specific vulnerabilities
output: Output format (screen, text, json)
key: API key for safety service
scan: Full environment scan
auto_install: Auto-install safety if missing
"""Generate requirements.txt files from Pipfile.lock.
def requirements(dev=False, dev_only=False, hash=False, exclude_markers=False, categories=None):
"""
Generate requirements.txt from Pipfile.lock.
Parameters:
dev: Include development packages
dev_only: Only development packages
hash: Include package hashes
exclude_markers: Exclude environment markers
categories: Specific categories to include
"""Usage examples:
pipenv requirements > requirements.txt # Generate requirements
pipenv requirements --dev --hash # Include dev deps with hashesAccess project information and locations.
def scripts():
"""List scripts from Pipfile."""
def open(module_name):
"""
Open module in editor.
Parameters:
module_name: Name of module to open
"""
def verify():
"""Verify Pipfile.lock hash is up-to-date."""Usage examples:
pipenv scripts # List available scripts
pipenv open requests # Open module in editor
pipenv verify # Verify lock file integrityThe CLI uses state objects to pass configuration between commands and business logic.
class State:
"""
Main state container with project, install state, and global options.
Attributes:
project: Project instance
installstate: Installation state
quiet: Quiet output flag
verbose: Verbose output flag
clear: Clear caches flag
python: Python version specification
"""
class InstallState:
"""
Installation-specific options and package lists.
Attributes:
packages: List of packages to install
dev: Development dependency flag
pre: Pre-release flag
system: System pip flag
"""
class LockOptions:
"""
Lock-specific options.
Attributes:
dev: Include development dependencies
pre: Allow pre-release packages
"""Reusable option decorators for CLI commands.
def pass_state(f):
"""Click decorator for state passing."""
def common_options(f):
"""Common CLI options: pypi-mirror, verbose, quiet, clear, python."""
def install_options(f):
"""Install-related options including packages, dev, pre, etc."""
def lock_options(f):
"""Lock-specific options including dev-only flag."""
def sync_options(f):
"""Sync-specific options."""
def general_options(f):
"""Common + site-packages options."""CLI context configuration for Click framework.
CONTEXT_SETTINGS = {
"help_option_names": ["-h", "--help"],
"auto_envvar_prefix": "PIPENV"
}The CLI automatically maps environment variables with the PIPENV_ prefix to corresponding command options.
Install with Tessl CLI
npx tessl i tessl/pypi-pipenv