Plugin API reference¶
This page documents the interfaces that plugins must implement.
Discovery¶
Discovery plugins locate Python interpreters for creating virtual environments.
- class virtualenv.discovery.discover.Discover(options)¶
Discover and provide the requested Python interpreter.
- Parameters:
options (
VirtualEnvOptions)
Create a new discovery mechanism.
- Parameters:
options (
VirtualEnvOptions) – the parsed options as defined withinadd_parser_arguments()
- classmethod add_parser_arguments(parser)¶
Add CLI arguments for this discovery mechanisms.
- Parameters:
parser (
ArgumentParser) – the CLI parser- Return type:
- abstractmethod run()¶
Discovers an interpreter.
- Return type:
- Returns:
the interpreter ready to use for virtual environment creation
- property interpreter: PythonInfo | None¶
- Returns:
the interpreter as returned by
run(), cached
PythonInfo¶
Discovery plugins return a PythonInfo object describing the located interpreter.
- class virtualenv.discovery.py_info.PythonInfo¶
Contains information for a Python interpreter.
- install_path(key)¶
Return the relative installation path for a given installation scheme key.
- property is_old_virtualenv: bool¶
Trueif this interpreter runs inside an old-style virtualenv (hasreal_prefix).
- sysconfig_path(key, config_var=None, sep='/')¶
Return the sysconfig install path for a scheme key, optionally substituting config variables.
- creators(refresh=False)¶
Return the available creators for this interpreter, cached unless
refreshisTrue.- Parameters:
refresh (
bool) – ifTrue, re-discover creators instead of using the cache- Return type:
CreatorSelector- Returns:
the creator selector for this interpreter
- property system_exec_prefix: str¶
The exec prefix of the system Python this interpreter is based on.
- property machine: str¶
The instruction set architecture (ISA) of this interpreter.
Derived from
sysconfig.get_platform(), which returns the platform identity string used by Python’s build system (e.g.macosx-14.0-arm64,linux-x86_64,win-amd64). The ISA is the last component of this string.For macOS
universal2fat binaries, falls back toplatform.machine()to report the actual runtime ISA (arm64orx86_64) rather than the build target.- Returns:
the ISA string, e.g.
arm64,x86_64,x86
- property spec: str¶
A specification string identifying this interpreter (e.g.
CPython3.13.2-64-arm64).
- classmethod clear_cache(app_data)¶
Clear all cached interpreter information from the application data store.
- satisfies(spec, impl_must_match)¶
Check if a given specification can be satisfied by this python interpreter instance.
- classmethod current(app_data=None)¶
Locate the current host interpreter information.
This might differ from the running interpreter if the host Python has been upgraded.
- classmethod current_system(app_data=None)¶
Locate the current system interpreter information, resolving through any virtualenv layers.
- classmethod from_exe(exe, app_data=None, raise_on_error=True, ignore_cache=False, resolve_to_host=True, env=None)¶
Given a path to an executable, get the python information.
- Parameters:
exe (
str) – path to the Python executableapp_data (
AppData|None) – the application data store for cachingraise_on_error (
bool) – ifTrue, raise on failure instead of returningNoneignore_cache (
bool) – ifTrue, bypass the cache and re-query the interpreterresolve_to_host (
bool) – ifTrue, resolve through virtualenv layers to the host interpreterenv (
Mapping[str,str] |None) – environment variables to use for subprocess calls
- Return type:
- Returns:
the interpreter information, or
Noneif discovery failed andraise_on_errorisFalse
- discover_exe(app_data, prefix, exact=True, env=None)¶
Discover a matching Python executable under a given prefix directory.
- Parameters:
- Return type:
- Returns:
the discovered interpreter information
App data¶
The application data interface used by plugins for caching.
- class virtualenv.app_data.base.AppData¶
Abstract storage interface for the virtualenv application.
- abstractmethod py_info(path)¶
Return a content store for cached interpreter information at the given path.
- Parameters:
path (
Path) – the interpreter executable path- Return type:
ContentStore- Returns:
a content store for the cached data
- abstractmethod embed_update_log(distribution, for_py_version)¶
Return a content store for the embed update log of a distribution.
- property transient: bool¶
Trueif this app data store is transient and does not persist across runs.
- abstractmethod wheel_image(for_py_version, name)¶
Return the path to a cached wheel image.
- ensure_extracted(path, to_folder=None)¶
Ensure a path is available on disk, extracting from zipapp if needed.
- abstractmethod extract(path, to_folder)¶
Extract a path from the zipapp to a location on disk.
Creators¶
Creator plugins build the virtual environment directory structure and install the Python interpreter.
- class virtualenv.create.creator.CreatorMeta¶
- class virtualenv.create.creator.Creator(options, interpreter)¶
A class that given a python Interpreter creates a virtual environment.
- Parameters:
options (
VirtualEnvOptions)interpreter (
PythonInfo)
Construct a new virtual environment creator.
- Parameters:
options (
VirtualEnvOptions) – the CLI option as parsed fromadd_parser_arguments()interpreter (
PythonInfo) – the interpreter to create virtual environment from
- classmethod can_create(interpreter)¶
Determine if we can create a virtual environment.
- Parameters:
interpreter (
PythonInfo) – the interpreter in question- Return type:
- Returns:
Noneif we can’t create, any other object otherwise that will be forwarded toadd_parser_arguments()
- classmethod add_parser_arguments(parser, interpreter, meta, app_data)¶
Add CLI arguments for the creator.
- Parameters:
parser (
ArgumentParser) – the CLI parserapp_data (
AppData) – the application data folderinterpreter (
PythonInfo) – the interpreter we’re asked to create virtual environment formeta (
CreatorMeta) – value as returned bycan_create()
- Return type:
- add_cachedir_tag()¶
Generate a file indicating that this is not meant to be backed up.
- setup_ignore_vcs()¶
Generate ignore instructions for version control systems.
Seeders¶
Seeder plugins install initial packages (like pip, setuptools, wheel) into the virtual environment.
- class virtualenv.seed.seeder.Seeder(options, enabled)¶
A seeder will install some seed packages into a virtual environment.
- Parameters:
options (
VirtualEnvOptions)enabled (
bool)
Create.
- Parameters:
options (
VirtualEnvOptions) – the parsed options as defined withinadd_parser_arguments()enabled (
bool) – a flag weather the seeder is enabled or not
- classmethod add_parser_arguments(parser, interpreter, app_data)¶
Add CLI arguments for this seed mechanisms.
- Parameters:
parser (
ArgumentParser) – the CLI parserapp_data (
AppData) – the CLI parserinterpreter (
PythonInfo) – the interpreter this virtual environment is based of
- Return type:
- abstractmethod run(creator)¶
Perform the seed operation.
- Parameters:
creator (
Creator) – the creator (based ofvirtualenv.create.creator.Creator) we used to create this virtual environment- Return type:
Activators¶
Activator plugins generate shell-specific activation scripts.
- class virtualenv.activation.activator.Activator(options)¶
Generates activate script for the virtual environment.
- Parameters:
options (
VirtualEnvOptions)
Create a new activator generator.
- Parameters:
options (
VirtualEnvOptions) – the parsed options as defined withinadd_parser_arguments()
- classmethod supports(interpreter)¶
Check if the activation script is supported in the given interpreter.
- Parameters:
interpreter (
PythonInfo) – the interpreter we need to support- Return type:
- Returns:
Trueif supported,Falseotherwise
- classmethod add_parser_arguments(parser, interpreter)¶
Add CLI arguments for this activation script.
- Parameters:
parser (
ArgumentParser) – the CLI parserinterpreter (
PythonInfo) – the interpreter this virtual environment is based of
- Return type:
- abstractmethod generate(creator)¶
Generate activate script for the given creator.
- Parameters:
creator (
Creator) – the creator (based ofvirtualenv.create.creator.Creator) we used to create this virtual environment- Return type: