1. Scott Sturdivant
  2. redmine



Redmine: Pythonic Wrapper

Redmine is a python wrapper for the Redmine REST API. Presently, it only has limited support for the Project and Issue types and GET methods.


Installation is just a simple pip install away!

$ pip install redmine


Getting started is straight forward; only the root URL to your redmine instance needs to be set.

>>> import redmine
>>> redmine.URL = 'http://localhost/redmine'

By instantiating the Redmine class, your project's heirarchy is created for you, where the attributes are the project's identifier.

>>> r = redmine.Redmine()
>>> r.toplevel
<Top Level Project, id: 1>
>>> r.toplevel.midlevel
<Mid Level Project, id: 2>
>>> r.toplevel.low_level
<Low Level Project, id: 3>


Projects with hyphens in their identifier will be converted to underscores.

Each Project has issues, and getting / filtering them is easy.

>>> issues = r.toplevel.issues
>>> len(issues)
>>> version_1_issues = [i for i in issues if i.version == '1.0']

Depending on the size of your project, querying the issues can be time consuming, so two helpers are provided.

>>> open_issues   = r.toplevel.open_issues
>>> closed_issues = r.toplevel.closed_issues


Redmine's queries by default include the subprojects. This wrapper changes that behavior and only returns the issues for the given project.

Finally, there is an Issue class.

>>> issue = redmine.Issue(123)
>>> issue
<Bug #2974, status: Closed, version: 3.0>

Practical Usage

An expected usage of this might exist in a commit hook that verifies certain criteria against a redmine install. For mercurial, when coupled with the hg-issues extension, certain checks become very simple.

Let's say you have a restriction where any commit referencing an Issue must be for an issue that is not closed. Given a list of issues found in the commit messages, your in-process hook can now do something along these lines:

>>> issues = [Issue(i) for i in ctx_issues]
>>> if [i in issues if i.status == 'Closed']:
...     reject()