Evergreen Python Client
evergreen-py is a Python client library for interacting with the Evergreen API, specifically supporting its V2 version. It allows developers to build Python tools for Evergreen or use it on the command line to retrieve data about Evergreen objects. The library is actively maintained with automatic deployments to PyPI on merges to the master branch, following a semver versioning scheme. The current version is 3.15.0.
Warnings
- gotcha Authentication requires an Evergreen username and API key. These are typically provided via an `.evergreen.yml` file or by setting `EVERGREEN_USERNAME` and `EVERGREEN_API_KEY` environment variables. Without these, API calls will fail.
- gotcha The `patch_from_diff` API function within `evergreen-py` explicitly requires the Evergreen CLI to be installed and available in the system's PATH. This is not a dependency installed by `pip install evergreen-py`.
- gotcha The `evergreen-py` library specifically supports the V2 version of the Evergreen API. Functionality from older API versions may not be available or behave differently.
Install
-
pip install evergreen-py
Imports
- EvgAuth
from evergreen.api import EvgAuth
- EvergreenApi
from evergreen.api import EvergreenApi
Quickstart
import os
from evergreen.api import EvgAuth, EvergreenApi
# It's recommended to set EVERGREEN_USERNAME and EVERGREEN_API_KEY as environment variables
username = os.environ.get('EVERGREEN_USERNAME', 'your_evergreen_username')
api_key = os.environ.get('EVERGREEN_API_KEY', 'your_evergreen_api_key')
# Ensure credentials are provided (replace with actual credentials or env vars)
if not username or not api_key:
print("Please set EVERGREEN_USERNAME and EVERGREEN_API_KEY environment variables or provide them directly.")
else:
auth = EvgAuth(username, api_key)
api = EvergreenApi.get_api(auth)
try:
project = api.project_by_id('mongodb-mongo-master')
print(f"Project Display Name: {project.display_name}")
except Exception as e:
print(f"Error fetching project: {e}. Please check your credentials and project ID.")