An API for virtualenv/pip
Project description
virtualenv is a tool to create isolated Python environments. Unfortunately, it does not expose a native Python API. This package aims to provide an API in the form of a wrapper around virtualenv.
It can be used to create and delete environments and perform package management inside the environment.
Full support is provided for Python 2.7 and Python 3.3+.
Installation
The latest stable release is available on PyPi:
$ pip install virtualenv-api
Please note that the distribution is named virtualenv-api, yet the Python package is named virtualenvapi.
Alternatively, you may fetch the latest version from git:
$ pip install git+https://github.com/sjkingo/virtualenv-api.git
Examples
To begin managing an environment (it will be created if it does not exist):
from virtualenvapi.manage import VirtualEnvironment
env = VirtualEnvironment('/path/to/environment/name')
You may also specify the Python interpreter to use in this environment by passing the python argument to the class constructor (new in 2.1.3):
env = VirtualEnvironment('/path/to/environment/name', python='python3')
Check if the mezzanine package is installed:
>>> env.is_installed('mezzanine')
False
Install the latest version of the mezzanine package:
>>> env.install('mezzanine')
A wheel of the latest version of the mezzanine package (new in 2.1.4):
>>> env.wheel('mezzanine')
Install version 1.4 of the django package (this is pip’s syntax):
>>> env.install('django==1.4')
Upgrade the django package to the latest version:
>>> env.upgrade('django')
Uninstall the mezzanine package:
>>> env.uninstall('mezzanine')
Packages may be specified as name only (to work on the latest version), using pip’s package syntax (e.g. django==1.4) or as a tuple of ('name', 'ver') (e.g. ('django', '1.4')).
A package may be installed directly from a git repository (must end with .git):
>>> env.install('git+git://github.com/sjkingo/cartridge-payments.git')
Instances of the environment provide an installed_packages property:
>>> env.installed_packages
[('django', '1.5'), ('wsgiref', '0.1.2')]
A list of package names is also available in the same manner:
>>> env.installed_package_names
['django', 'wsgiref']
Search for a package on PyPI (changed in 2.1.5: this now returns a dictionary instead of list):
>>> env.search('virtualenv-api')
{'virtualenv-api': 'An API for virtualenv/pip'}
>>> len(env.search('requests'))
231
The old functionality (pre 2.1.5) of env.search may be used:
>>> list(env.search('requests').items())
[('virtualenv-api', 'An API for virtualenv/pip')]
Verbose output from each command is available in the environment’s build.log file, which is appended to with each operation. Any errors are logged to build.err.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file virtualenv-api-2.1.6.tar.gz
.
File metadata
- Download URL: virtualenv-api-2.1.6.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bba463c20fecbf546e747d58c68bd2fcbabab3213c0d1ca824e91b3b1da0135 |
|
MD5 | ca855ba2112a6004ca0230d2c213fdbf |
|
BLAKE2b-256 | b1ea39208b3435ca0b17c04886de787ffc4b9ad0226c24ef91f5b4af3d8a5563 |
File details
Details for the file virtualenv_api-2.1.6-py2.py3-none-any.whl
.
File metadata
- Download URL: virtualenv_api-2.1.6-py2.py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00d6e1d334ad395fda96d655e314b95e283f32791fa532f46acf2cc2918824b3 |
|
MD5 | aec715f3d33f85cfe35df8062e14e48d |
|
BLAKE2b-256 | 1963dcb1443d981a3ca7236388ffe8f5469b8a1a06f90394be75273d21917310 |