Python Redmine Library
Python-Redmine is a comprehensive library for programmatic interaction with the Redmine project management application. It allows users to manage issues, projects, users, and other Redmine resources through a Pythonic interface. The current version is 2.5.0, with new releases typically coming a few times a year, often including support for RedmineUP's Pro Edition plugins.
Common errors
-
from python_redmine import Redmine ModuleNotFoundError: No module named 'python_redmine'
cause Incorrect import path. The main package for importing classes is `redminelib`, not `python_redmine`.fixChange your import statement to `from redminelib import Redmine`. -
redminelib.exceptions.ResourceNotFoundError: The resource you are trying to access doesn't exist.
cause Attempted to access a Redmine resource (e.g., issue, project, user) with an ID that does not exist or is inaccessible.fixVerify the ID you are using is correct and that the user associated with the API key has permissions to view that resource. Check Redmine directly to confirm the resource's existence and visibility. -
redminelib.exceptions.RedmineError: No 'X-Redmine-API-Key' header found.
cause The Redmine API key was not provided or is incorrect, or the Redmine server is not configured to accept API key authentication.fixEnsure you are passing a valid API key to the `Redmine` constructor (e.g., `key='YOUR_API_KEY'`). Verify that API authentication is enabled in your Redmine server settings (Administration -> Settings -> Authentication -> 'Enable REST API'). -
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))cause The Redmine URL is incorrect, the server is offline, or there is a network issue preventing connection to the Redmine instance.fixDouble-check the `REDMINE_URL` you are using. Ensure the Redmine server is running and accessible from where you are running your Python code. Verify any firewalls or proxies are not blocking the connection.
Warnings
- breaking Python 2.x, 3.3, 3.5, and 3.6 support has been dropped. Python-Redmine now requires Python >= 3.7.
- breaking The `requests` package, previously vendored, became an external dependency. If you were relying on it being bundled, your code might fail.
- gotcha Minimum `requests` version requirements are periodically updated (e.g., to >= 2.31.0 in v2.5.0, >= 2.28.2 in v2.4.0). Using an older `requests` version might lead to dependency conflicts or unexpected behavior.
- gotcha Some features, like the `/my/account` endpoint for non-admin users (`redmine.user.get('me')`), News API, or RedmineUP plugin support, require a minimum Redmine API version.
Install
-
pip install python-redmine
Imports
- Redmine
from python_redmine import Redmine
from redminelib import Redmine
- RedmineError
from redminelib.exceptions import RedmineError
Quickstart
import os
from redminelib import Redmine
from redminelib.exceptions import ResourceNotFoundError
# Replace with your Redmine URL and API Key
REDMINE_URL = os.environ.get('REDMINE_URL', 'http://localhost:3000')
REDMINE_API_KEY = os.environ.get('REDMINE_API_KEY', 'YOUR_API_KEY_HERE')
try:
redmine = Redmine(REDMINE_URL, key=REDMINE_API_KEY)
# Get current user
me = redmine.user.get('current')
print(f"Connected to Redmine as: {me.firstname} {me.lastname} ({me.login})")
# Get a list of projects
projects = redmine.project.all(limit=5)
print("\nFirst 5 Projects:")
for project in projects:
print(f" - {project.name} (ID: {project.id})")
# Try to get a specific issue
try:
issue = redmine.issue.get(1)
print(f"\nIssue #1: {issue.subject} (Status: {issue.status.name})")
except ResourceNotFoundError:
print("\nIssue #1 not found.")
except Exception as e:
print(f"An error occurred: {e}")