python -c: Run a One-Liner in CI
Execute a quick Python snippet without a file.
python -c runs the Python code passed as a string. CI scripts use it for quick assertions - verifying an import works or printing a value - without a temp file.
What it does
Executes the supplied program string and exits. The exit code reflects success or an unhandled exception, so it doubles as a check in a pipeline step.
Common usage
Terminal
python -c "import sys; print(sys.version)"
python -c "import requests; print(requests.__version__)"
python -c "import myapp; print('import ok')"Common CI gotcha: shell quoting
Mixing the shell’s quotes with Python string quotes breaks the snippet. Wrap the program in double quotes and use single quotes inside, or vice versa.
Terminal
# Use double outside, single inside:
python -c "import json; print(json.dumps({'ok': True}))"Options
| Flag | Does |
|---|---|
| -c CMD | Run CMD as a program |
| -W ACTION | Set a warnings filter |
Related guides
python -u: Unbuffered Output for CI LogsWhy python -u (unbuffered stdout/stderr) makes Python logs appear in real time in CI, the PYTHONUNBUFFERED al…
python --version: Check the Active InterpreterHow python --version reports the interpreter version, why CI should verify it before installing, and the vers…
python -m pytest: Run Tests with the Project on sys.pathWhy python -m pytest beats a bare pytest in CI, how it adds the current directory to sys.path, and the import…