Skip to main content

An API for virtualenv/pip

Project description

Build Status Latest version BSD License

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')

If you have already activated a virtualenv and wish to operate on it, simply call VirtualEnvironment with no arguments:

env = VirtualEnvironment()

New in 2.1.7:

An optional argument readonly may be provided (defaults to False) that will prevent all operations that could potentially modify the environment.

  • 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')
  • Upgrade all packages to their latest versions (new in 2.1.7):

>>> env.upgrade_all()
  • 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')

New in 2.1.10:

  • A package can be installed in pip’s editable mode by prefixing the package name with -e (this is pip’s syntax):

>>> env.install('-e git+https://github.com/stephenmcd/cartridge.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

virtualenv-api-2.1.12.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

virtualenv_api-2.1.12-py2.py3-none-any.whl (10.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file virtualenv-api-2.1.12.tar.gz.

File metadata

File hashes

Hashes for virtualenv-api-2.1.12.tar.gz
Algorithm Hash digest
SHA256 28fc72cdfd1b9b0af4f8d2bf74f2227b4e66bd3dca31e17dfa0f04fc36a1a1c1
MD5 6fa909c3d3449e3073c1c091f0cb274f
BLAKE2b-256 20ae2f3bef63848656ce8f13ac9c9a7d2f3e89198b0382e1cc014315a7fcc3b2

See more details on using hashes here.

File details

Details for the file virtualenv_api-2.1.12-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for virtualenv_api-2.1.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0ffe482006165f7c0e77b5d31390b14437031b393a9b62e6b40a028918b8f8f5
MD5 cb1a77c6dab7807758d6f852dbd04a32
BLAKE2b-256 879d2dba1ee5f0e6c5188f566e3f005f90e23fbd708c39a38d364c6fc5393233

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page