Overview
Thepython-copr library provides a Python interface to interact with the Copr build service API. It allows you to programmatically manage projects, builds, packages, and other Copr resources.
Installation
Install the python-copr package using pip:Dependencies
The library requires the following dependencies (installed automatically):filelock- File locking supportrequests- HTTP libraryrequests-toolbelt- Additional utilities for requestssetuptools- Python package utilitiesmunch- Dictionary-like object access
Quick Start
Basic Usage
Using Configuration File
Alternatively, use a configuration file located at~/.config/copr:
You can obtain your API credentials from the Copr API page after creating an account.
Client Class
TheClient class is the main entry point for interacting with the Copr API.
Constructor
config(dict): Configuration dictionary with the following keys:copr_url(str): Base URL of the Copr instancelogin(str): API login from /api pagetoken(str): API token from /api pageusername(str): Your Copr usernamegssapi(bool, optional): Use GSSAPI authenticationencrypted(bool, optional): Require HTTPS (default: True)
Class Methods
create_from_config_file(path=None)
Create a Client instance from a configuration file.
Parameters:
path(str, optional): Path to config file (defaults to~/.config/copr)
Client instance
Example:
Proxy Classes
The Client provides access to various proxy objects for different API resources:Available Proxies
| Proxy | Attribute | Description |
|---|---|---|
ProjectProxy | client.project_proxy | Manage projects |
BuildProxy | client.build_proxy | Create and manage builds |
PackageProxy | client.package_proxy | Manage packages |
MockChrootProxy | client.mock_chroot_proxy | Query available chroots |
ProjectChrootProxy | client.project_chroot_proxy | Manage project chroots |
BuildChrootProxy | client.build_chroot_proxy | Query build chroot details |
MonitorProxy | client.monitor_proxy | Monitor builds |
WebhookProxy | client.webhook_proxy | Manage webhooks |
ProjectProxy
Manage Copr projects (repositories).Methods
get(ownername, projectname)
Retrieve a single project.
Parameters:
ownername(str): Owner of the projectprojectname(str): Name of the project
get_list(ownername=None, pagination=None)
List projects.
Parameters:
ownername(str, optional): Filter by ownerpagination(dict, optional): Pagination parameters
search(query, pagination=None)
Search projects by fulltext query.
Parameters:
query(str): Search querypagination(dict, optional): Pagination parameters
add(ownername, projectname, chroots, **kwargs)
Create a new project.
Parameters:
ownername(str): Owner of the projectprojectname(str): Name for the new projectchroots(list): List of chroot names (e.g.,["fedora-39-x86_64"])description(str, optional): Project descriptioninstructions(str, optional): Installation instructionshomepage(str, optional): Project homepage URLcontact(str, optional): Contact informationadditional_repos(list, optional): External repositoriesunlisted_on_hp(bool, optional): Hide from homepage (default: False)enable_net(bool, optional): Allow network access during buildsauto_prune(bool, optional): Auto-delete old builds (default: True)delete_after_days(int, optional): Delete project after N daysbootstrap(str, optional): Bootstrap mode (default,on,off,image)isolation(str, optional): Mock isolation (default,simple,nspawn)follow_fedora_branching(bool, optional): Auto-enable new Fedora branches
edit(ownername, projectname, **kwargs)
Edit an existing project.
Parameters: Same as add() (all optional except ownername and projectname)
Returns: Munch object with updated project
delete(ownername, projectname)
Delete a project.
Parameters:
ownername(str): Owner of the projectprojectname(str): Name of the project to delete
fork(ownername, projectname, dstownername, dstprojectname, confirm=False)
Fork a project to another location.
Parameters:
ownername(str): Source project ownerprojectname(str): Source project namedstownername(str): Destination ownerdstprojectname(str): Destination project nameconfirm(bool): Confirm if destination exists
BuildProxy
Create and manage builds.Methods
get(build_id)
Retrieve build details.
Parameters:
build_id(int): Build ID
get_list(ownername, projectname, packagename=None, status=None, pagination=None)
List builds for a project.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepackagename(str, optional): Filter by package namestatus(str, optional): Filter by statuspagination(dict, optional): Pagination parameters
create_from_url(ownername, projectname, url, buildopts=None, project_dirname=None)
Create a build from a SRPM URL.
Parameters:
ownername(str): Project ownerprojectname(str): Project nameurl(str): URL to SRPM filebuildopts(dict, optional): Build options (chroots, timeouts, etc.)project_dirname(str, optional): Subdirectory in project
create_from_file(ownername, projectname, path, buildopts=None, project_dirname=None)
Create a build from a local SRPM file.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepath(str): Path to local SRPM filebuildopts(dict, optional): Build optionsproject_dirname(str, optional): Subdirectory in project
create_from_scm(ownername, projectname, clone_url, committish="", subdirectory="", spec="", scm_type="git", source_build_method="rpkg", buildopts=None, project_dirname=None)
Create a build from a Git/SVN repository.
Parameters:
ownername(str): Project ownerprojectname(str): Project nameclone_url(str): Repository URLcommittish(str, optional): Branch, tag, or commit hashsubdirectory(str, optional): Subdirectory containing packagespec(str, optional): Path to spec file (relative to subdirectory)scm_type(str, optional): Version control type (gitorsvn)source_build_method(str, optional): Build method (rpkg,tito,make_srpm)buildopts(dict, optional): Build optionsproject_dirname(str, optional): Subdirectory in project
create_from_pypi(ownername, projectname, pypi_package_name, pypi_package_version=None, python_versions=None, buildopts=None, project_dirname=None)
Create a build from a PyPI package.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepypi_package_name(str): PyPI package namepypi_package_version(str, optional): Specific version (default: latest)python_versions(list, optional): Python versions to build for (default:[3, 2])buildopts(dict, optional): Build optionsproject_dirname(str, optional): Subdirectory in project
cancel(build_id)
Cancel a running build.
Parameters:
build_id(int): Build ID to cancel
delete(build_id)
Delete a build.
Parameters:
build_id(int): Build ID to delete
PackageProxy
Manage package configurations within projects.Methods
get(ownername, projectname, packagename, with_latest_build=False, with_latest_succeeded_build=False)
Get package details.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepackagename(str): Package namewith_latest_build(bool, optional): Include latest build infowith_latest_succeeded_build(bool, optional): Include latest successful build
get_list(ownername, projectname, pagination=None, with_latest_build=False, with_latest_succeeded_build=False)
List packages in a project.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepagination(dict, optional): Pagination parameterswith_latest_build(bool, optional): Include latest build infowith_latest_succeeded_build(bool, optional): Include latest successful build
add(ownername, projectname, packagename, source_type, source_dict)
Add a package configuration to a project.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepackagename(str): Package namesource_type(str): Source type (git,scm,pypi,rubygems,custom)source_dict(dict): Source configuration (depends on source_type)
edit(ownername, projectname, packagename, source_type=None, source_dict=None)
Edit package configuration.
Parameters: Same as add() (source parameters are optional)
Returns: Munch object with updated package
build(ownername, projectname, packagename, buildopts=None, project_dirname=None)
Create a build from package configuration.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepackagename(str): Package namebuildopts(dict, optional): Build optionsproject_dirname(str, optional): Subdirectory in project
delete(ownername, projectname, packagename)
Delete a package from a project.
Parameters:
ownername(str): Project ownerprojectname(str): Project namepackagename(str): Package name to delete
Helper Functions
config_from_file(path=None)
Load configuration from a file.
Parameters:
path(str, optional): Path to config file (defaults to~/.config/copr)
wait(waitable, interval=30, callback=None, timeout=0)
Wait for builds to complete.
Parameters:
waitable(Munch or list): Build object(s) to wait forinterval(int, optional): Seconds between checks (default: 30)callback(callable, optional): Function called on each iterationtimeout(int, optional): Maximum seconds to wait (0 = unlimited)
succeeded(builds)
Check if all builds succeeded.
Parameters:
builds(Munch or list): Build object(s) to check
Exceptions
The library defines several exception classes:Exception Hierarchy
CoprException- Base exception classCoprRequestException- API request failedCoprNoResultException- No result data returnedCoprTimeoutException- Request timed outCoprValidationException- Invalid data sent to APICoprConfigException- Configuration file errorCoprAuthException- Authentication failure
Example Error Handling
Munch Objects
API responses are returned asMunch objects, which allow both dictionary and attribute-style access:
Build Options
Many build methods accept abuildopts dictionary parameter. Common options include:
Authentication Methods
The library supports multiple authentication methods:API Token (Default)
Standard authentication using login and token from~/.config/copr: