api#

Collection of conda's high-level APIs.

Classes#

Solver

Beta While in beta, expect both major and minor changes across minor releases.

SubdirData

Beta While in beta, expect both major and minor changes across minor releases.

PackageCacheData

Beta While in beta, expect both major and minor changes across minor releases.

PrefixData

Beta While in beta, expect both major and minor changes across minor releases.

Attributes#

DepsModifier#
UpdateModifier#
class Solver(prefix, channels, subdirs=(), specs_to_add=(), specs_to_remove=())#

Beta While in beta, expect both major and minor changes across minor releases.

A high-level API to conda's solving logic. Three public methods are provided to access a solution in various forms.

Beta

Parameters:
  • prefix (str) -- The conda prefix / environment location for which the Solver is being instantiated.

  • channels (Sequence[Channel]) -- A prioritized list of channels to use for the solution.

  • subdirs (Sequence[str]) -- A prioritized list of subdirs to use for the solution.

  • specs_to_add (set[MatchSpec]) -- The set of package specs to add to the prefix.

  • specs_to_remove (set[MatchSpec]) -- The set of package specs to remove from the prefix.

solve_final_state(update_modifier=NULL, deps_modifier=NULL, prune=NULL, ignore_pinned=NULL, force_remove=NULL)#

Beta While in beta, expect both major and minor changes across minor releases.

Gives the final, solved state of the environment.

Parameters:
  • deps_modifier (DepsModifier) -- An optional flag indicating special solver handling for dependencies. The default solver behavior is to be as conservative as possible with dependency updates (in the case the dependency already exists in the environment), while still ensuring all dependencies are satisfied. Options include * NO_DEPS * ONLY_DEPS * UPDATE_DEPS * UPDATE_DEPS_ONLY_DEPS * FREEZE_INSTALLED

  • prune (bool) -- If True, the solution will not contain packages that were previously brought into the environment as dependencies but are no longer required as dependencies and are not user-requested.

  • ignore_pinned (bool) -- If True, the solution will ignore pinned package configuration for the prefix.

  • force_remove (bool) -- Forces removal of a package without removing packages that depend on it.

Returns:

In sorted dependency order from roots to leaves, the package references for the solved state of the environment.

Return type:

tuple[PackageRef]

solve_for_diff(update_modifier=NULL, deps_modifier=NULL, prune=NULL, ignore_pinned=NULL, force_remove=NULL, force_reinstall=False)#

Beta While in beta, expect both major and minor changes across minor releases.

Gives the package references to remove from an environment, followed by the package references to add to an environment.

Parameters:
Returns:

A two-tuple of PackageRef sequences. The first is the group of packages to remove from the environment, in sorted dependency order from leaves to roots. The second is the group of packages to add to the environment, in sorted dependency order from roots to leaves.

Return type:

tuple[PackageRef], tuple[PackageRef]

solve_for_transaction(update_modifier=NULL, deps_modifier=NULL, prune=NULL, ignore_pinned=NULL, force_remove=NULL, force_reinstall=False)#

Beta While in beta, expect both major and minor changes across minor releases.

Gives an UnlinkLinkTransaction instance that can be used to execute the solution on an environment.

Parameters:
Return type:

UnlinkLinkTransaction

class SubdirData(channel)#

Beta While in beta, expect both major and minor changes across minor releases.

High-level management and usage of repodata.json for subdirs.

Beta While in beta, expect both major and minor changes across minor releases.

Parameters:

channel (str or Channel) --

The target subdir for the instance. Must either be a url that includes a subdir or a Channel that includes a subdir. e.g.:

query(package_ref_or_match_spec)#

Beta While in beta, expect both major and minor changes across minor releases.

Run a query against this specific instance of repodata.

Parameters:

package_ref_or_match_spec (PackageRef or MatchSpec or str) -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

Returns:

tuple[PackageRecord]

static query_all(package_ref_or_match_spec, channels=None, subdirs=None)#

Beta While in beta, expect both major and minor changes across minor releases.

Run a query against all repodata instances in channel/subdir matrix.

Parameters:
  • package_ref_or_match_spec (PackageRef or MatchSpec or str) -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

  • channels (Iterable[Channel or str] or None) -- An iterable of urls for channels or Channel objects. If None, will fall back to context.channels.

  • subdirs (Iterable[str] or None) -- If None, will fall back to context.subdirs.

Returns:

tuple[PackageRecord]

iter_records()#

Beta While in beta, expect both major and minor changes across minor releases.

Returns:

A generator over all records contained in the repodata.json

instance. Warning: this is a generator that is exhausted on first use.

Return type:

Iterable[PackageRecord]

reload()#

Beta While in beta, expect both major and minor changes across minor releases.

Update the instance with new information. Backing information (i.e. repodata.json) is lazily downloaded/loaded on first use by the other methods of this class. You should only use this method if you are sure you have outdated data.

Returns:

SubdirData

class PackageCacheData(pkgs_dir)#

Beta While in beta, expect both major and minor changes across minor releases.

High-level management and usage of package caches.

Beta While in beta, expect both major and minor changes across minor releases.

Parameters:

pkgs_dir (str)

property is_writable#

Beta While in beta, expect both major and minor changes across minor releases.

Indicates if the package cache location is writable or read-only.

Returns:

bool

get(package_ref, default=NULL)#

Beta While in beta, expect both major and minor changes across minor releases.

Parameters:
  • package_ref (PackageRef) -- A PackageRef instance representing the key for the PackageCacheRecord being sought.

  • default -- The default value to return if the record does not exist. If not specified and no record exists, KeyError is raised.

Returns:

PackageCacheRecord

query(package_ref_or_match_spec)#

Beta While in beta, expect both major and minor changes across minor releases.

Run a query against this specific package cache instance.

Parameters:

package_ref_or_match_spec (PackageRef or MatchSpec or str) -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

Returns:

tuple[PackageCacheRecord]

static query_all(package_ref_or_match_spec, pkgs_dirs=None)#

Beta While in beta, expect both major and minor changes across minor releases.

Run a query against all package caches.

Parameters:
  • package_ref_or_match_spec (PackageRef or MatchSpec or str) -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

  • pkgs_dirs (Iterable[str] or None) -- If None, will fall back to context.pkgs_dirs.

Returns:

tuple[PackageCacheRecord]

iter_records()#

Beta While in beta, expect both major and minor changes across minor releases.

Returns:

A generator over all records contained in the package

cache instance. Warning: this is a generator that is exhausted on first use.

Return type:

Iterable[PackageCacheRecord]

static first_writable(pkgs_dirs=None)#

Beta While in beta, expect both major and minor changes across minor releases.

Get an instance object for the first writable package cache.

Parameters:

pkgs_dirs (Iterable[str]) -- If None, will fall back to context.pkgs_dirs.

Returns:

An instance for the first writable package cache.

Return type:

PackageCacheData

reload()#

Beta While in beta, expect both major and minor changes across minor releases.

Update the instance with new information. Backing information (i.e. contents of the pkgs_dir) is lazily loaded on first use by the other methods of this class. You should only use this method if you are sure you have outdated data.

Returns:

PackageCacheData

class PrefixData(prefix_path)#

Beta While in beta, expect both major and minor changes across minor releases.

High-level management and usage of conda environment prefixes.

Beta While in beta, expect both major and minor changes across minor releases.

Parameters:

prefix_path (str)

property is_writable#

Beta While in beta, expect both major and minor changes across minor releases.

Indicates if the prefix is writable or read-only.

Returns:

True if the prefix is writable. False if read-only. None if the prefix does not exist as a conda environment.

Return type:

bool or None

get(package_ref, default=NULL)#

Beta While in beta, expect both major and minor changes across minor releases.

Parameters:
  • package_ref (PackageRef) -- A PackageRef instance representing the key for the PrefixRecord being sought.

  • default -- The default value to return if the record does not exist. If not specified and no record exists, KeyError is raised.

Returns:

PrefixRecord

query(package_ref_or_match_spec)#

Beta While in beta, expect both major and minor changes across minor releases.

Run a query against this specific prefix instance.

Parameters:

package_ref_or_match_spec (PackageRef or MatchSpec or str) -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

Returns:

tuple[PrefixRecord]

iter_records()#

Beta While in beta, expect both major and minor changes across minor releases.

Returns:

A generator over all records contained in the prefix.

Warning: this is a generator that is exhausted on first use.

Return type:

Iterable[PrefixRecord]

reload()#

Beta While in beta, expect both major and minor changes across minor releases.

Update the instance with new information. Backing information (i.e. contents of the conda-meta directory) is lazily loaded on first use by the other methods of this class. You should only use this method if you are sure you have outdated data.

Returns:

PrefixData