Rest api ẅith python » History » Revision 8

« Previous | Revision 8/18 (diff) | Next »
Ian Epperson, 2013-02-07 20:46
Updated link for the Python library. Added an example for it too.

Using the REST API with Python

Here is the two well-known options for using REST API with python.

  1. PyActiveResource
  2. Python library

PyActiveResource example:

# Importing pyactiveresource
from pyactiveresource.activeresource import ActiveResource

class Issue(ActiveResource):
    _site = ''
    _user = 'username'
    _password = 'password'

# Get issues
issues = Issue.find()

# Get a specific issue, from its id
issue = Issue.find(1345)

# Issue attributes

# Updating an attribute

Python library example:

Suppose Eric fell ill and was out for several days. You need to crawl through the project called Parrot and move any due date for issues assigned to Eric out by two more weeks.

The dateutil library contains a handy method called reativedelta for calculating relative dates.

<code class="python">
from redmine import Redmine
from dateutil.relativedelta import relativedelta

server = Redmine('', username='Me', password='seakrit')
project = server.projects['parrot']

# Find Eric in the user data
for u in server.users:
    if u.firstname == 'Eric' and u.lastname == 'Idle':
       user = u
    raise Exception("Didn't find Eric Idle in the user dateabase")

# Extend issues in project assigned to user by two weeks
for issue in project.issues(
    if issue.due_date is not None:
       issue.due_date += relativedelta(weeks=+2)'Giving Eric more time to complete - he was out ill')

Updated by Ian Epperson almost 11 years ago · 8 revisions