Python Redmine

97
Python Redmine Documentation Release Max Tepkeev February 20, 2015

description

Python Redmine

Transcript of Python Redmine

  • Python Redmine DocumentationRelease

    Max Tepkeev

    February 20, 2015

  • Contents

    1 Features 3

    2 Contacts and Support 5

    3 Donations and Sponsorship 7

    4 Copyright and License 9

    5 Table of contents 115.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.2 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145.4 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185.5 Advanced Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.6 Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815.7 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815.8 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835.9 Changelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    Python Module Index 91

    i

  • ii

  • Python Redmine Documentation, Release

    Python Redmine is a library for communicating with a Redmine project management application. Redmine exposessome of its data via REST API for which Python Redmine provides a simple but powerful Pythonic API inspired bya well-known Django ORM:

    >>> from redmine import Redmine

    >>> redmine = Redmine(http://demo.redmine.org, username=foo, password=bar)>>> project = redmine.project.get(vacation)

    >>> project.id30404

    >>> project.identifiervacation

    >>> project.created_ondatetime.datetime(2013, 12, 31, 13, 27, 47)

    >>> project.issues

    >>> project.issues[0]

    >>> dir(project.issues[0])[assigned_to, author, created_on, description, done_ratio,due_date, estimated_hours, id, priority, project, relations,start_date, status, subject, time_entries, tracker, updated_on]

    >>> project.issues[0].subjectVacation

    >>> project.issues[0].time_entries

    Contents 1

  • Python Redmine Documentation, Release

    2 Contents

  • CHAPTER 1

    Features

    Supports 100% of Redmine API features

    Supports Python 2.6 - 3.4, PyPy and PyPy3

    Extensively documented

    Provides ORM-style Pythonic API

    3

  • Python Redmine Documentation, Release

    4 Chapter 1. Features

  • CHAPTER 2

    Contacts and Support

    I will be glad to get your feedback, pull requests, issues, whatever. Feel free to contact me for any questions.

    5

  • Python Redmine Documentation, Release

    6 Chapter 2. Contacts and Support

  • CHAPTER 3

    Donations and Sponsorship

    If you like this project and want to support it you have 3 options:

    1. Just give this project a star at the top of the GitHub repository. That doesnt cost you anything but makes theauthor happier.

    2. You can express your gratitude via Gratipay.

    3. Become a sponsor. Contact me via tepkeev at gmail dot com if you are interested in becoming asponsor and we will discuss the terms and conditions.

    7

  • Python Redmine Documentation, Release

    8 Chapter 3. Donations and Sponsorship

  • CHAPTER 4

    Copyright and License

    Python Redmine is licensed under Apache 2.0 license. Check the License for details.

    9

  • Python Redmine Documentation, Release

    10 Chapter 4. Copyright and License

  • CHAPTER 5

    Table of contents

    5.1 Installation

    5.1.1 Dependencies

    Python Redmine relies heavily on great Requests library by Kenneth Reitz for all the http(s) calls.

    5.1.2 Conflicts

    Python Redmine cant be used together with PyRedmine because they both use same module name, i.e. redminewhich causes unexpected behaviour for both packages. That means that you have to uninstall PyRedmine beforeinstalling Python Redmine.

    5.1.3 PyPI

    The recommended way to install is from Python Package Index (PyPI) with pip:

    $ pip install python-redmine

    or with easy_install:

    $ easy_install python-redmine

    If the PyPI is down, you can also install Python Redmine from one of its mirrors, e.g. from Crate.IO:

    $ pip install -i http://simple.crate.io/ python-redmine

    5.1.4 GitHub

    Python Redmine is actively developed on GitHub. If you want to get latest development sources you have to clone therepository:

    $ git clone git://github.com/maxtepkeev/python-redmine.git

    Once you have the sources, you can install it into your site-packages:

    $ python setup.py install

    You can also install latest stable development version via pip:

    11

  • Python Redmine Documentation, Release

    $ pip install git+https://github.com/maxtepkeev/python-redmine.git@master

    5.2 Configuration

    5.2.1 Redmine

    To start making requests to Redmine you have to check the box Enable REST API in Administration -> Settings ->Authentication and click the Save button.

    Hint: Sometimes it is a good idea to create a special user in Redmine which will be used only for the calls toRedmines REST API.

    5.2.2 Parameters

    Configuring Python Redmine is extremely easy, the first thing you have to do is to import the Redmine object, whichwill represent the connection to Redmine server:

    from redmine import Redmine

    Location

    Now you need to configure the Redmine object and pass it a few parameters. The only required parameter is theRedmine location (without the forward slash in the end):

    redmine = Redmine(http://demo.redmine.org)

    Authentication

    Most of the time, the API requires authentication. It can be done in 2 different ways:

    using users regular login and password:

    redmine = Redmine(http://demo.redmine.org, username=foo, password=bar)

    using users API key which is a handy way to avoid putting a password in a script:

    redmine = Redmine(http://demo.redmine.org, key=b244397884889a29137643be79c83f1d470c1e2fac)

    The API key can be found on users account page when logged in, on the right-hand pane of the default layout.

    Impersonation

    As of Redmine 2.2.0, you can impersonate user through the REST API. It must be set to a user login, e.g. jsmith. Thisonly works when using the API with an administrator account, this will be ignored when using the API with a regularuser account.

    redmine = Redmine(http://demo.redmine.org, impersonate=jsmith)

    If the login specified does not exist or is not active, you will get an exception.

    12 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Version

    There are a lot of different Redmine versions out there and different versions support different resources and features.To be sure that everything will work as expected you need to tell Python Redmine what version of Redmine do youuse:

    redmine = Redmine(http://demo.redmine.org, version=2.3.3)

    DateTime Formats

    Python Redmine automatically converts Redmines date/datetime strings to Pythons date/datetime objects:

    2013-12-31 -> datetime.date(2013, 12, 31)2013-12-31T13:27:47Z -> datetime.datetime(2013, 12, 31, 13, 27, 47)

    Starting from Python Redmine 0.7.0 the conversion also works backwards, i.e. you can use Pythons date/datetimeobjects when setting resource attributes or in ResourceManager methods, e.g. filter():

    datetime.date(2013, 12, 31) -> 2013-12-31datetime.datetime(2013, 12, 31, 13, 27, 47) -> 2013-12-31T13:27:47Z

    If the conversion doesnt work for you and you receive strings instead of objects, you have a different datetime for-matting than default. To make the conversion work you have to tell Redmine object what datetime formatting do youuse, e.g. if the string returned is 31.12.2013T13:27:47Z:

    redmine = Redmine(http://demo.redmine.org, date_format=%d.%m.%Y, datetime_format=%d.%m.%YT%H:%M:%SZ)

    Exception Control

    New in version 0.4.0.

    If a requested attribute on a resource object doesnt exist, Python Redmine will raise an exception by default. Some-times this may not be the desired behaviour. Python Redmine provides a way to control this type of exception.

    You can completely turn it OFF for all resources:

    redmine = Redmine(https://redmine.url, raise_attr_exception=False)

    Or you can turn it ON only for some resources via a list or tuple of resource class names:

    redmine = Redmine(https://redmine.url, raise_attr_exception=(Project, Issue, WikiPage))

    Connection Options

    New in version 0.3.1.

    Python Redmine uses Requests library for all the http(s) calls to Redmine server. Requests provides sensible defaultconnection options, but sometimes you may have a need to change them. For example if your Redmine server usesSSL but the certificate is invalid you need to set a Requestss verify option to False:

    redmine = Redmine(https://redmine.url, requests={verify: False})

    Full list of available connection options can be found in the Requests documentation.

    Hint: Storing settings right in the code is a bad habit. Instead store them in some configuration file and then importthem, for example if you use Django, you can create settings for Python Redmine in projects settings.py file and thenimport them in the code, e.g.:

    5.2. Configuration 13

  • Python Redmine Documentation, Release

    # settings.pyREDMINE_URL = http://demo.redmine.orgREDMINE_KEY = b244397884889a29137643be79c83f1d470c1e2fac

    # somewhere in the codefrom django.conf import settingsfrom redmine import Redmine

    redmine = Redmine(settings.REDMINE_URL, key=settings.REDMINE_KEY)

    5.3 Operations

    Now when you have configured your Redmine object, you can start making operations on the Redmine. Redmine hasa conception of resources, i.e. resource is an entity which can be used in Redmines REST API. All operations on theresources are provided by the ResourceManager object which you usually dont have to use directly. Not all resourcessupport every operation, if resource doesnt support the requested operation, an exception will be thrown.

    5.3.1 Create

    New in version 0.2.0.

    Python Redmine provides 2 create operation methods: create and new. Unfortunately Redmine doesnt support thecreation of some resources via REST API. You can read more about it in each resources documentation.

    create

    Creates new resource with given fields and saves it to the Redmine.

    >>> project = redmine.project.create(name=Vacation, identifier=vacation, description=foo, homepage=http://foo.bar, is_public=True, parent_id=345, inherit_members=True, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}])>>> project

    new

    New in version 0.4.0.

    Creates new empty resource but doesnt save it to the Redmine. This is useful if you want to set some resource fieldslater based on some condition(s) and only after that save it to the Redmine.

    >>> project = redmine.project.new()>>> project.name = Vacation>>> project.identifier = vacation>>> project.description = foo>>> project.homepage = http://foo.bar>>> project.is_public = True>>> project.parent_id = 345>>> project.inherit_members = True>>> project.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> project.save()True

    14 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    5.3.2 Read

    New in version 0.1.0.

    Python Redmine provides 3 read operation methods: get, all and filter. Each of this methods support differentkeyword arguments depending on the resource used and method called. You can read more about it in each resourcesdocumentation.

    get

    Returns requested Resource object either by integer id or by string identifier:

    >>> project = redmine.project.get(vacation)>>> project.nameVacation>>> project[name] # You can access Resource attributes this way tooVacation

    Note: Resource object provides 2 ways to introspect itself: dir(). Returns all the attributes Resource has as a list.

    dir(redmine.project.get(vacation))

    list(). Returns all the attributes with its values Resource has as a list of tuples.

    list(redmine.project.get(vacation))

    Hint: Under some circumstances Redmine doesnt return all the data about Resource, fortunately Resource objectprovides a convenient refresh() method which will get all the available data:

    redmine.project.get(vacation).refresh()

    all

    Returns a ResourceSet object that contains all the requested Resource objects:

    >>> projects = redmine.project.all()>>> projects

    filter

    Returns a ResourceSet object that contains Resource objects filtered by some condition(s):

    >>> issues = redmine.issue.filter(project_id=vacation)>>> issues

    Hint: ResourceSet object supports limit and offset, i.e. if you need to get only some portion of Resource objects, inthe form of [offset:limit] or as keyword arguments:

    5.3. Operations 15

  • Python Redmine Documentation, Release

    redmine.project.all()[:135] # Returns only the first 135 projectsredmine.project.all(limit=135) # Returns only the first 135 projectsredmine.issue.filter(project_id=vacation)[10:3] # Returns only 3 issues starting from 10thredmine.issue.filter(project_id=vacation, offset=10, limit=3) # Returns only 3 issues starting from 10th

    Please note, that keyword arguments have a higher priority, e.g.:

    redmine.project.all(limit=10)[:20] # Returns 10 projects and not 20

    Hint: ResourceSet object provides 5 helper methods get(), filter(), update(), delete() and values(): get. Returns a single resource from the ResourceSet by resource id:

    redmine.project.all().get(30404, None) # Returns None if a Resource is not found

    filter. Returns a ResourceSet with requested resource ids:

    redmine.project.all().filter((30404, 30405, 30406, 30407))

    update. Updates fields of all resources in a ResourceSet with the given values and returns an updated Resource-Set object, e.g., the following assigns issues of a project vacation with ids of 30404 and 30405 to the user withid of 547:

    New in version 1.0.0.

    redmine.project.get(vacation).issues.filter((30404, 30405)).update(assigned_to_id=547)

    delete. Deletes all resources in a ResourceSet, e.g. the following deletes all issues from the vacation project:

    New in version 1.0.0.

    redmine.project.get(vacation).issues.delete()

    values. Returns a ValuesResourceSet a ResourceSet subclass that returns dictionaries when used as aniterable, rather than resource-instance objects. Each of those dictionaries represents a resource, with the keyscorresponding to the attribute names of resource objects. This example compares the dictionaries of values()with the normal resource objects:

    New in version 1.0.0.

    >>> list(redmine.issue_status.all(limit=1))[]>>> list(redmine.issue_status.all(limit=1).values())[{id: 1, is_default: True, name: New}]

    16 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    The values() method takes optional positional arguments, *fields, which specify field names to which resourcefields should be limited. If you specify the fields, each dictionary will contain only the field keys/values for thefields you specify. If you dont specify the fields, each dictionary will contain a key and value for every field inthe resource:

    >>> list(redmine.issue_status.all(limit=1).values())[{id: 1, is_default: True, name: New}]>>> list(redmine.issue_status.all(limit=1).values(id, name))[{id: 1, name: New}]

    ResourceSet object also provides some attributes:

    limit. What limit value was used to retrieve this ResourceSet:

    redmine.project.all().limit

    offset. What offset value was used to retrieve this ResourceSet:

    redmine.project.all().offset

    total_count. How much resources of current resource type there are available in Redmine:

    New in version 0.4.0.

    redmine.project.all().total_count

    Note: ResourceSet object is lazy, i.e. it doesnt make any requests to Redmine when it is created and is evaluatedonly when some of these conditions are met:

    Iteration. A ResourceSet is iterable and it is evaluated when you iterate over it.

    for project in redmine.project.all():print(project.name)

    len(). A ResourceSet is evaluated when you call len() on it and returns the length of the list.

    len(redmine.project.all())

    list(). Force evaluation of a ResourceSet by calling list() on it.

    list(redmine.project.all())

    Index. A ResourceSet is also evaluated when you request some of its Resources by index.

    redmine.project.all()[0] # Returns the first Resource in the ResourceSet

    5.3.3 Update

    New in version 0.4.0.

    Python Redmine provides 2 update operation methods: update and save. Unfortunately Redmine doesnt supportupdates on some resources via REST API. You can read more about it in each resources documentation.

    5.3. Operations 17

  • Python Redmine Documentation, Release

    update

    Updates a resource with given fields and saves it to the Redmine.

    >>> redmine.project.update(1, name=Vacation, description=foo, homepage=http://foo.bar, is_public=True, parent_id=345, inherit_members=True, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}])True

    save

    Saves the current state of a resource to the Redmine.

    >>> project = redmine.project.get(1)>>> project.name = Vacation>>> project.description = foo>>> project.homepage = http://foo.bar>>> project.is_public = True>>> project.parent_id = 345>>> project.inherit_members = True>>> project.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> project.save()True

    5.3.4 Delete

    New in version 0.3.0.

    Resources can be deleted via deletemethod. Unfortunately Redmine doesnt support the deletion of some resourcesvia REST API. You can read more about it in each resources documentation.

    >>> redmine.project.delete(1)True

    Warning: Deleted resources cant be restored. Use this method carefully.

    5.4 Resources

    5.4.1 Issue

    Supported by Redmine starting from version 1.0

    Manager

    All operations on the issue resource are provided via its manager. To get access to it you have to callredmine.issue where redmine is a configured redmine object. See the Configuration about how to configureredmine object.

    18 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new issue resource with given fields and saves it to the Redmine.

    Parameters

    project_id (integer or string) (required). Id or identifier of issues project.

    subject (string) (required). Issue subject.

    tracker_id (integer) (optional). Issue tracker id.

    description (string) (optional). Issue description.

    status_id (integer) (optional). Issue status id.

    priority_id (integer) (optional). Issue priority id.

    category_id (integer) (optional). Issue category id.

    fixed_version_id (integer) (optional). Issue version id.

    is_private (boolean) (optional). Whether issue is private.

    assigned_to_id (integer) (optional). Issue will be assigned to this user id.

    watcher_user_ids (list or tuple) (optional). User ids who will be watching this issue.

    parent_issue_id (integer) (optional). Parent issue id.

    start_date (string or date object) (optional). Issue start date.

    due_date (string or date object) (optional). Issue end date.

    estimated_hours (integer) (optional). Issue estimated hours.

    done_ratio (integer) (optional). Issue done ratio.

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    uploads (list or tuple)

    path (required). Absolute path to the file that should be uploaded.

    filename (optional). Name of the file after upload.

    description (optional). Description of the file.

    content_type (optional). Content type of the file.

    Returns Issue resource object

    >>> issue = redmine.issue.create(project_id=vacation, subject=Vacation, tracker_id=8, description=foo, status_id=3, priority_id=7, assigned_to_id=123, watcher_user_ids=[123], parent_issue_id=345, start_date=2014-01-01, due_date=2014-02-01, estimated_hours=4, done_ratio=40, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}], uploads=[{path: /absolute/path/to/file}, {path: /absolute/path/to/file2}])>>> issue

    new

    redmine.managers.ResourceManager.new()Creates new empty issue resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    5.4. Resources 19

  • Python Redmine Documentation, Release

    Returns Issue resource object

    >>> issue = redmine.issue.new()>>> issue.project_id = vacation>>> issue.subject = Vacation>>> issue.tracker_id = 8>>> issue.description = foo>>> issue.status_id = 3>>> issue.priority_id = 7>>> issue.assigned_to_id = 123>>> issue.watcher_user_ids = [123]>>> issue.parent_issue_id = 345>>> issue.start_date = date(2014, 1, 1)>>> issue.due_date = date(2014, 2, 1)>>> issue.estimated_hours = 4>>> issue.done_ratio = 40>>> issue.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> issue.uploads = [{path: /absolute/path/to/file}, {path: /absolute/path/to/file2}]>>> issue.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id, **params)Returns single issue resource from the Redmine by its id.

    Parameters

    resource_id (integer) (required). Id of the issue.

    include (string)

    children

    attachments

    relations

    changesets

    journals

    watchers

    Returns Issue resource object

    >>> issue = redmine.issue.get(34441, include=children,journals,watchers)>>> issue

    Hint: New in version 0.4.0.

    Issue resource object provides you with on demand includes. On demand includes are the other resource objectswrapped in a ResourceSet which are associated with an Issue resource object. Keep in mind that on demand includes

    20 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    are retrieved in a separate request, that means that if the speed is important it is recommended to use get method witha include keyword argument. The on demand includes provided by the Issue resource object are the same as in theget method above:

    >>> issue = redmine.issue.get(34441)>>> issue.journals

    Hint: Issue resource object provides you with some relations. Relations are the other resource objects wrapped ina ResourceSet which are somehow related to an Issue resource object. The relations provided by the Issue resourceobject are:

    relations

    time_entries

    >>> issue = redmine.issue.get(34441)>>> issue.time_entries

    all

    redmine.managers.ResourceManager.all(**params)Returns all issue resources from the Redmine.

    Parameters

    sort (string) (optional). Column to sort with. Append :desc to invert the order.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> issues = redmine.issue.all(sort=category:desc)>>> issues

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns issue resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (optional). Id or identifier of issues project.

    subproject_id (integer or string) (optional). Get issues from the subproject with the givenid. You can use project_id=X, subproject_id=!* to get only the issues of a given project andnone of its subprojects.

    tracker_id (integer) (optional). Get issues from the tracker with the given id.

    query_id (integer) (optional). Get issues for the given query id.

    status_id (integer or string)

    open - open issues

    5.4. Resources 21

  • Python Redmine Documentation, Release

    closed - closed issues

    * - all issues

    id - status id

    assigned_to_id (integer) (optional). Get issues which are assigned to the given user id.To get the issues assigned to the user whose credentials were used to access the API passme as a string.

    cf_x (string) (optional). Get issues with the given value for custom field with an ID of x.

    sort (string) (optional). Column to sort with. Append :desc to invert the order.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> issues = redmine.issue.filter(project_id=vacation, subproject_id=!*, created_on=>>> issues

    Hint: You can also get issues from a project, tracker, issue status or user resource objects directly using issuesrelation:

    >>> project = redmine.project.get(vacation)>>> project.issues

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of an issue resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Issue id.

    project_id (integer) (optional). Issue project id.

    subject (string) (optional). Issue subject.

    tracker_id (integer) (optional). Issue tracker id.

    description (string) (optional). Issue description.

    notes (string) (optional). Issue journal note.

    status_id (integer) (optional). Issue status id.

    priority_id (integer) (optional). Issue priority id.

    category_id (integer) (optional). Issue category id.

    fixed_version_id (integer) (optional). Issue version id.

    is_private (boolean) (optional). Whether issue is private.

    assigned_to_id (integer) (optional). Issue will be assigned to this user id.

    22 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    parent_issue_id (integer) (optional). Parent issue id.

    start_date (string or date object) (optional). Issue start date.

    due_date (string or date object) (optional). Issue end date.

    estimated_hours (integer) (optional). Issue estimated hours.

    done_ratio (integer) (optional). Issue done ratio.

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    uploads (list or tuple)

    path (required). Absolute path to the file that should be uploaded.

    filename (optional). Name of the file after upload.

    description (optional). Description of the file.

    content_type (optional). Content type of the file.

    Returns True

    >>> redmine.issue.update(1, project_id=1, subject=Vacation, tracker_id=8, description=foo, notes=A journal note, status_id=3, priority_id=7, assigned_to_id=123, parent_issue_id=345, start_date=2014-01-01, due_date=2014-02-01, estimated_hours=4, done_ratio=40, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}], uploads=[{path: /absolute/path/to/file}, {path: /absolute/path/to/file2}])True

    save

    redmine.resources.Issue.save()Saves the current state of an issue resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    >>> issue = redmine.issue.get(1)>>> issue.project_id = 1>>> issue.subject = Vacation>>> issue.tracker_id = 8>>> issue.description = foo>>> issue.notes = A journal note>>> issue.status_id = 3>>> issue.priority_id = 7>>> issue.assigned_to_id = 123>>> issue.parent_issue_id = 345>>> issue.start_date = date(2014, 1, 1)>>> issue.due_date = date(2014, 2, 1)>>> issue.estimated_hours = 4>>> issue.done_ratio = 40>>> issue.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> issue.uploads = [{path: /absolute/path/to/file}, {path: /absolute/path/to/file2}]>>> issue.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single issue resource from the Redmine by its id.

    5.4. Resources 23

  • Python Redmine Documentation, Release

    Parameters resource_id (integer) (required). Issue id.

    Returns True

    >>> redmine.issue.delete(1)True

    Watchers

    New in version 0.5.0.

    Python Redmine provides 2 methods to work with issue watchers: add and remove.

    add

    redmine.resources.Issue.Watcher.add(user_id)Adds a user to issue watchers list by its id.

    Parameters user_id (integer) (required). User id.

    Returns True

    >>> issue = redmine.issue.get(1)>>> issue.watcher.add(1)True

    remove

    redmine.resources.Issue.Watcher.remove(user_id)Removes a user from issue watchers list by its id.

    Parameters user_id (integer) (required). User id.

    Returns True

    >>> issue = redmine.issue.get(1)>>> issue.watcher.remove(1)True

    5.4.2 Project

    Supported by Redmine starting from version 1.0

    Manager

    All operations on the project resource are provided via its manager. To get access to it you have to callredmine.project where redmine is a configured redmine object. See the Configuration about how to con-figure redmine object.

    24 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new project resource with given fields and saves it to the Redmine.

    Parameters

    name (string) (required). Project name.

    identifier (string) (required). Project identifier.

    description (string) (optional). Project description.

    homepage (string) (optional). Project homepage url.

    is_public (boolean) (optional). Whether project is public.

    parent_id (integer) (optional). Projects parent project id.

    inherit_members (boolean) (optional). If project inherits parent projects members.

    tracker_ids (list) (optional). The ids of trackers for this project.

    issue_custom_field_ids (list) (optional). The ids of issue custom fields for this project.

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    enabled_module_names (list) (optional). The names of enabled modules for this project(Redmine >= 2.6.0 only).

    Returns Project resource object

    >>> project = redmine.project.create(name=Vacation, identifier=vacation, description=foo, homepage=http://foo.bar, is_public=True, parent_id=345, inherit_members=True, tracker_ids=[1, 2], issue_custom_field_ids=[1, 2], custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}], enabled_module_names=[calendar, documents, files, gantt])>>> project

    new

    redmine.managers.ResourceManager.new()Creates new empty project resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns Project resource object

    >>> project = redmine.project.new()>>> project.name = Vacation>>> project.identifier = vacation>>> project.description = foo>>> project.homepage = http://foo.bar>>> project.is_public = True>>> project.parent_id = 345>>> project.inherit_members = True>>> project.tracker_ids = [1, 2]>>> project.issue_custom_field_ids = [1, 2]>>> project.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> project.enabled_module_names = [calendar, documents, files, gantt]>>> project.save()True

    5.4. Resources 25

  • Python Redmine Documentation, Release

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id, **params)Returns single project resource from the Redmine by its id or identifier.

    Parameters

    resource_id (integer or string) (required). Project id or identifier.

    include (string)

    trackers

    issue_categories

    enabled_modules (Redmine >= 2.6.0 only)

    Returns Project resource object

    >>> project = redmine.project.get(vacation, include=trackers,issue_categories,enabled_modules)>>> project

    Hint: New in version 0.4.0.

    Project resource object provides you with on demand includes. On demand includes are the other resource objectswrapped in a ResourceSet which are associated with a Project resource object. Keep in mind that on demand includesare retrieved in a separate request, that means that if the speed is important it is recommended to use get method witha include keyword argument. The on demand includes provided by the Project resource object are the same as inthe get method above:

    >>> project = redmine.project.get(vacation)>>> project.trackers

    Hint: Project resource object provides you with some relations. Relations are the other resource objects wrapped ina ResourceSet which are somehow related to a Project resource object. The relations provided by the Project resourceobject are:

    wiki_pages

    memberships

    issue_categories

    versions

    news

    issues

    time_entries (available from v1.0.0)

    deals (available from v1.0.0 and only if CRM plugin is installed)

    contacts (available from v1.0.0 and only if CRM plugin is installed)

    26 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    deal_categories (available from v1.0.0 and only if CRM plugin 3.3.0 and higher is installed)

    >>> project = redmine.project.get(vacation)>>> project.issues

    all

    redmine.managers.ResourceManager.all(**params)Returns all project resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    include (string)

    trackers

    issue_categories

    enabled_modules

    Returns ResourceSet object

    >>> projects = redmine.project.all(offset=10, limit=100)>>> projects

    filter

    Not supported by Redmine

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a project resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Project id.

    name (string) (optional). Project name.

    description (string) (optional). Project description.

    homepage (string) (optional). Project homepage url.

    is_public (boolean) (optional). Whether project is public.

    parent_id (integer) (optional). Projects parent project id.

    inherit_members (boolean) (optional). If project inherits parent projects members.

    tracker_ids (list) (optional). The ids of trackers for this project.

    5.4. Resources 27

  • Python Redmine Documentation, Release

    issue_custom_field_ids (list) (optional). The ids of issue custom fields for this project.

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    enabled_module_names (list) (optional). The names of enabled modules for this project(Redmine >= 2.6.0 only).

    Returns True

    >>> redmine.project.update(1, name=Vacation, description=foo, homepage=http://foo.bar, is_public=True, parent_id=345, inherit_members=True, tracker_ids=[1, 2], issue_custom_field_ids=[1, 2], custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}], enabled_module_names=[calendar, documents, files, gantt])True

    save

    redmine.resources.Project.save()Saves the current state of a project resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    >>> project = redmine.project.get(1)>>> project.name = Vacation>>> project.description = foo>>> project.homepage = http://foo.bar>>> project.is_public = True>>> project.parent_id = 345>>> project.inherit_members = True>>> project.tracker_ids = [1, 2]>>> project.issue_custom_field_ids = [1, 2]>>> project.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> project.enabled_module_names = [calendar, documents, files, gantt]>>> project.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single project resource from the Redmine by its id or identifier.

    Parameters resource_id (integer or string) (required). Project id or identifier.

    Returns True

    >>> redmine.project.delete(1)True

    5.4.3 Project Membership

    Supported by Redmine starting from version 1.4

    28 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Manager

    All operations on the project membership resource are provided via its manager. To get access to it you have to callredmine.project_membership where redmine is a configured redmine object. See the Configuration abouthow to configure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new project membership resource with given fields and saves it to the Redmine.

    Parameters

    project_id (integer or string) (required). Id or identifier of the project.

    user_id (integer) (required). Id of the user to add to the project.

    role_ids (list or tuple) (required). Role ids to add to the user in this project.

    Returns ProjectMembership resource object

    >>> membership = redmine.project_membership.create(project_id=vacation, user_id=1, role_ids=[1, 2])>>> membership

    new

    redmine.managers.ResourceManager.new()Creates new empty project membership resource but doesnt save it to the Redmine. This is useful if you wantto set some resource fields later based on some condition(s) and only after that save it to the Redmine. Validattributes are the same as for create method above.

    Returns ProjectMembership resource object

    >>> membership = redmine.project_membership.new()>>> membership.project_id = vacation>>> membership.user_id = 1>>> membership.role_ids = [1, 2]>>> membership.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single project membership resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Project membership id.

    Returns ProjectMembership resource object

    5.4. Resources 29

  • Python Redmine Documentation, Release

    >>> membership = redmine.project_membership.get(521)>>> membership

    all

    Not supported by Redmine

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns project membership resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (required). Id or identifier of the project.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> memberships = redmine.project_membership.filter(project_id=vacation)>>> memberships

    Hint: You can also get project memberships from a project resource object directly using memberships relation:>>> project = redmine.project.get(vacation)>>> project.memberships

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a project membership resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Project membership id.

    role_ids (list or tuple) (required). Role ids to add to the user in this project.

    Returns True

    >>> redmine.project_membership.update(1, role_ids=[1, 2])True

    30 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    save

    redmine.resources.ProjectMembership.save()Saves the current state of a project membership resource to the Redmine. Fields that can be changed are thesame as for update method above.

    Returns True

    >>> membership = redmine.project_membership.get(1)>>> membership.role_ids = [1, 2]>>> membership.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single project membership resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Project membership id.

    Returns True

    >>> redmine.project_membership.delete(1)True

    5.4.4 User

    Supported by Redmine starting from version 1.1

    Manager

    All operations on the user resource are provided via its manager. To get access to it you have to call redmine.userwhere redmine is a configured redmine object. See the Configuration about how to configure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new user resource with given fields and saves it to the Redmine.

    Parameters

    login (string) (required). User login.

    password (string) (optional). User password.

    firstname (string) (required). User name.

    lastname (string) (required). User surname.

    mail (string) (required). User email.

    auth_source_id (integer) (optional). Authentication mode id.

    5.4. Resources 31

  • Python Redmine Documentation, Release

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    Returns User resource object

    >>> user = redmine.user.create(login=jsmith, password=qwerty, firstname=John, lastname=Smith, [email protected], auth_source_id=1, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}])>>> user

    new

    redmine.managers.ResourceManager.new()Creates new empty user resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns User resource object

    >>> user = redmine.user.new()>>> user.login = jsmith>>> user.password = qwerty>>> user.firstname = John>>> user.lastname = Smith>>> user.mail = [email protected]>>> user.auth_source_id = 1>>> user.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> user.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id, **params)Returns single user resource from the Redmine by its id.

    Parameters

    resource_id (integer) (required). Id of the user.

    include (string)

    memberships

    groups

    Returns User resource object

    >>> user = redmine.user.get(17, include=memberships,groups)>>> user

    Hint: You can easily get the details of the user whose credentials were used to access the API:>>> user = redmine.user.get(current)>>> user

    Hint: New in version 0.4.0.

    32 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    User resource object provides you with on demand includes. On demand includes are the other resource objectswrapped in a ResourceSet which are associated with a User resource object. Keep in mind that on demand includesare retrieved in a separate request, that means that if the speed is important it is recommended to use get method witha include keyword argument. The on demand includes provided by the User resource object are the same as in theget method above:

    >>> user = redmine.user.get(17)>>> user.groups

    Hint: New in version 1.0.0.

    User resource object provides you with some relations. Relations are the other resource objects wrapped in a Re-sourceSet which are somehow related to a User resource object. The relations provided by the User resource objectare:

    issues

    time_entries

    deals (only available if CRM plugin is installed)

    contacts (only available if CRM plugin is installed)

    >>> user = redmine.user.get(17)>>> user.issues

    all

    redmine.managers.ResourceManager.all(**params)Returns all user resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> users = redmine.user.all(offset=10, limit=100)>>> users

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns user resources that match the given lookup parameters.

    5.4. Resources 33

  • Python Redmine Documentation, Release

    Parameters

    status (integer)

    0 - anonymous

    1 - active (default)

    2 - registered

    3 - locked

    name (string) (optional). Filter users on their login, firstname, lastname and mail. If thepattern contains a space, it will also return users whose firstname match the first word orlastname match the second word.

    group_id (integer) (optional). Get only users who are members of the given group.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> users = redmine.user.filter(offset=10, limit=100, status=3)>>> users

    Hint: You can also get users from a group resource object directly using users on demand includes:>>> group = redmine.group.get(524)>>> group.users

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a user resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). User id.

    login (string) (optional). User login.

    password (string) (optional). User password.

    firstname (string) (optional). User name.

    lastname (string) (optional). User surname.

    mail (string) (optional). User email.

    auth_source_id (integer) (optional). Authentication mode id.

    custom_fields (list) (optional). Custom fields in the form of [{id: 1, value: foo}].

    Returns True

    >>> redmine.user.update(1, login=jsmith, password=qwerty, firstname=John, lastname=Smith, [email protected], auth_source_id=1, custom_fields=[{id: 1, value: foo}, {id: 2, value: bar}])True

    34 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    save

    redmine.resources.User.save()Saves the current state of a user resource to the Redmine. Fields that can be changed are the same as for updatemethod above.

    Returns True

    >>> user = redmine.user.get(1)>>> user.login = jsmith>>> user.password = qwerty>>> user.firstname = John>>> user.lastname = Smith>>> user.mail = [email protected]>>> user.auth_source_id = 1>>> user.custom_fields = [{id: 1, value: foo}, {id: 2, value: bar}]>>> user.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single user resource from the Redmine by its id.

    Parameters resource_id (integer) (required). User id.

    Returns True

    >>> redmine.user.delete(1)True

    5.4.5 Time Entry

    Supported by Redmine starting from version 1.1

    Manager

    All operations on the time entry resource are provided via its manager. To get access to it you have to callredmine.time_entry where redmine is a configured redmine object. See the Configuration about how toconfigure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new time entry resource with given fields and saves it to the Redmine.

    Parameters

    issue_id or project_id (integer) (required). The issue id or project id to log time on.

    5.4. Resources 35

  • Python Redmine Documentation, Release

    hours (integer) (required). The number of spent hours.

    spent_on (string or date object) (optional). The date the time was spent (current date ifnot set).

    activity_id (integer) (optional). The id of the time activity. This parameter is requiredunless a default activity is defined in Redmine.

    comments (string) (optional). Short description for the entry (255 characters max).

    Returns TimeEntry resource object

    >>> time_entry = redmine.time_entry.create(issue_id=123, spent_on=2014-01-14, hours=3, activity_id=10, comments=hello)>>> time_entry

    new

    redmine.managers.ResourceManager.new()Creates new empty time entry resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns TimeEntry resource object

    >>> time_entry = redmine.time_entry.new()>>> time_entry.issue_id = 123>>> time_entry.spent_on = date(2014, 1, 14)>>> time_entry.hours = 3>>> time_entry.activity_id = 10>>> time_entry.comments = hello>>> time_entry.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single time entry resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the time entry.

    Returns TimeEntry resource object

    >>> time_entry = redmine.time_entry.get(374)>>> time_entry

    all

    redmine.managers.ResourceManager.all(**params)Returns all time entry resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    36 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> time_entries = redmine.time_entry.all(offset=10, limit=100)>>> time_entries

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns time entry resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (optional). Get time entries from the project with the givenid.

    issue_id (integer) (optional). Get time entries from the issue with the given id.

    user_id (integer) (optional). Get time entries for the user with the given id.

    spent_on (string or date object) (optional). Redmine >= 2.3.0 only. Date when hours wasspent.

    from_date (string or date object) (optional). New in version 0.4.0. Limit time entriesfrom this date.

    to_date (string or date object) (optional). New in version 0.4.0. Limit time entries untilthis date.

    hours (string) (optional). Get only time entries that are =, >=, >> time_entries = redmine.time_entry.filter(offset=10, limit=100, project_id=vacation, hours=>=8)>>> time_entries

    Hint: You can also get time entries from an issue resource object and starting from 1.0.0 project and user resourceobjects directly using time_entries relation:

    >>> issue = redmine.issue.get(34213)>>> issue.time_entries

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a time entry resource and saves them to the Redmine.

    Parameters

    5.4. Resources 37

  • Python Redmine Documentation, Release

    resource_id (integer) (required). Time entry id.

    issue_id or project_id (integer) (optional). The issue id or project id to log time on.

    hours (integer) (optional). The number of spent hours.

    spent_on (string or date object) (optional). The date the time was spent.

    activity_id (integer) (optional). The id of the time activity.

    comments (string) (optional). Short description for the entry (255 characters max).

    Returns True

    >>> redmine.time_entry.update(1, issue_id=123, spent_on=2014-01-14, hours=3, activity_id=10, comments=hello)True

    save

    redmine.resources.TimeEntry.save()Saves the current state of a time entry resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    >>> time_entry = redmine.time_entry.get(1)>>> time_entry.issue_id = 123>>> time_entry.spent_on = date(2014, 1, 14)>>> time_entry.hours = 3>>> time_entry.activity_id = 10>>> time_entry.comments = hello>>> time_entry.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single time entry resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Time entry id.

    Returns True

    >>> redmine.time_entry.delete(1)True

    5.4.6 News

    Supported by Redmine starting from version 1.1

    Manager

    All operations on the news resource are provided via its manager. To get access to it you have to call redmine.newswhere redmine is a configured redmine object. See the Configuration about how to configure redmine object.

    38 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Create methods

    Not supported by Redmine

    Read methods

    get

    Not supported by Redmine

    all

    redmine.managers.ResourceManager.all(**params)Returns all news resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> news = redmine.news.all(offset=10, limit=100)>>> news

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns news resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (required). Id or identifier of news project.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> news = redmine.news.filter(project_id=vacation)>>> news

    Hint: You can also get news from a project resource object directly using news relation:>>> project = redmine.project.get(vacation)>>> project.news

    Update methods

    Not supported by Redmine

    5.4. Resources 39

  • Python Redmine Documentation, Release

    Delete methods

    Not supported by Redmine

    5.4.7 Issue Relation

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the issue relation resource are provided via its manager. To get access to it you have to callredmine.issue_relation where redmine is a configured redmine object. See the Configuration about howto configure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new issue relation resource with given fields and saves it to the Redmine.

    Parameters

    issue_id (integer) (required). Creates a relation for the issue of given id.

    issue_to_id (integer) (required). Id of the related issue.

    relation_type (string)

    relates

    duplicates

    duplicated

    blocks

    blocked

    precedes

    follows

    delay (integer) (optional). Delay in days for a precedes or follows relation.

    Returns IssueRelation resource object

    >>> relation = redmine.issue_relation.create(issue_id=12345, issue_to_id=54321, relation_type=precedes, delay=5)>>> relation

    new

    redmine.managers.ResourceManager.new()Creates new empty issue relation resource but doesnt save it to the Redmine. This is useful if you want to setsome resource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributesare the same as for create method above.

    40 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Returns IssueRelation resource object

    >>> relation = redmine.issue_relation.new()>>> relation.issue_id = 12345>>> relation.issue_to_id = 54321>>> relation.relation_type = precedes>>> relation.delay = 5>>> relation.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single issue relation resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the issue relation.

    Returns IssueRelation resource object

    >>> relation = redmine.issue_relation.get(606)>>> relation

    all

    Not supported by Redmine

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns issue relation resources that match the given lookup parameters.

    Parameters

    issue_id (integer) (required). Get relations from the issue with the given id.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> relations = redmine.issue_relation.filter(issue_id=6543)>>> relations

    Hint: You can also get issue relations from an issue resource object directly using relations relation:>>> issue = redmine.issue.get(6543)>>> issue.relations

    5.4. Resources 41

  • Python Redmine Documentation, Release

    Update methods

    Not supported by Redmine

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single issue relation resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Issue relation id.

    Returns True

    >>> redmine.issue_relation.delete(1)True

    5.4.8 Version

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the version resource are provided via its manager. To get access to it you have to callredmine.version where redmine is a configured redmine object. See the Configuration about how to con-figure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new version resource with given fields and saves it to the Redmine.

    Parameters

    project_id (integer or string) (required). Id or identifier of versions project.

    name (string) (required). Version name.

    status (string)

    open (default)

    locked

    closed

    sharing (string)

    none (default)

    descendants

    hierarchy

    tree

    42 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    system

    due_date (string or date object) (optional). Expiration date.

    description (string) (optional). Version description.

    wiki_page_title (string) (optional). Version wiki page title.

    Returns Version resource object

    >>> version = redmine.version.create(project_id=vacation, name=Vacation, status=open, sharing=none, due_date=2014-01-30, description=my vacation, wiki_page_title=Vacation)>>> version

    new

    redmine.managers.ResourceManager.new()Creates new empty version resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns Version resource object

    >>> version = redmine.version.new()>>> version.project_id = vacation>>> version.name = Vacation>>> version.status = open>>> version.sharing = none>>> version.due_date = date(2014, 1, 30)>>> version.description = my vacation>>> version.wiki_page_title = Vacation>>> version.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single version resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the version.

    Returns Version resource object

    >>> version = redmine.version.get(1)>>> version

    all

    Not supported by Redmine

    5.4. Resources 43

  • Python Redmine Documentation, Release

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns version resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (required). Id or identifier of versions project.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> versions = redmine.version.filter(project_id=vacation)>>> versions

    Hint: You can also get versions from a project resource object directly using versions relation:>>> project = redmine.project.get(vacation)>>> project.versions

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a version resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Version id.

    name (string) (optional). Version name.

    status (string)

    open (default)

    locked

    closed

    sharing (string)

    none (default)

    descendants

    hierarchy

    tree

    system

    due_date (string or date object) (optional). Expiration date.

    description (string) (optional). Version description.

    wiki_page_title (string) (optional). Version wiki page title.

    44 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Returns True

    >>> redmine.version.update(1, name=Vacation, status=open, sharing=none, due_date=2014-01-30, description=my vacation, wiki_page_title=Vacation)True

    save

    redmine.resources.Version.save()Saves the current state of a version resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    >>> version = redmine.version.get(1)>>> version.name = Vacation>>> version.status = open>>> version.sharing = none>>> version.due_date = date(2014, 1, 30)>>> version.description = my vacation>>> version.wiki_page_title = Vacation>>> version.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single version resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Version id.

    Returns True

    >>> redmine.version.delete(1)True

    5.4.9 Wiki Page

    Supported by Redmine starting from version 2.2

    Manager

    All operations on the wiki page resource are provided via its manager. To get access to it you have to callredmine.wiki_page where redmine is a configured redmine object. See the Configuration about how to con-figure redmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new wiki page resource with given fields and saves it to the Redmine.

    5.4. Resources 45

  • Python Redmine Documentation, Release

    Parameters

    project_id (integer or string) (required). Id or identifier of wiki pages project.

    title (string) (required). Title of the wiki page.

    text (string) (required). Text of the wiki page.

    comments (string) (optional). Comments of the wiki page.

    Returns WikiPage resource object

    >>> wiki_page = redmine.wiki_page.create(project_id=vacation, title=FooBar, text=foo, comments=bar)>>> wiki_page

    new

    redmine.managers.ResourceManager.new()Creates new empty wiki page resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns WikiPage resource object

    >>> wiki_page = redmine.wiki_page.new()>>> wiki_page.project_id = vacation>>> wiki_page.title = FooBar>>> wiki_page.text = foo>>> wiki_page.comments = bar>>> wiki_page.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id, **params)Returns single wiki page resource from the Redmine by its title.

    Parameters

    resource_id (string) (required). Title of the wiki page.

    project_id (integer or string) (required). Id or identifier of wiki pages project.

    version (integer) (optional). Version of the wiki page.

    include (string)

    attachments

    Returns WikiPage resource object

    >>> wiki_page = redmine.wiki_page.get(Photos, project_id=vacation, version=12, include=attachments)>>> wiki_page

    Hint: New in version 0.4.0.

    46 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    WikiPage resource object provides you with on demand includes. On demand includes are the other resource objectswrapped in a ResourceSet which are associated with a WikiPage resource object. Keep in mind that on demandincludes are retrieved in a separate request, that means that if the speed is important it is recommended to use getmethod with a include keyword argument. The on demand includes provided by the WikiPage resource object arethe same as in the get method above:

    >>> wiki_page = redmine.wiki_page.get(524)>>> wiki_page.attachments

    all

    Not supported by Redmine

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns wiki page resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (required). Id or identifier of wiki pages project.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> wiki_pages = redmine.wiki_page.filter(project_id=vacation)>>> wiki_pages

    Hint: You can also get wiki pages from a project resource object directly using wiki_pages relation:>>> project = redmine.project.get(vacation)>>> project.wiki_pages

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a wiki page resource and saves them to the Redmine.

    Parameters

    resource_id (string) (required). Title of the wiki page.

    project_id (integer or string) (required). Id or identifier of wiki pages project.

    5.4. Resources 47

  • Python Redmine Documentation, Release

    title (string) (optional). Title of the wiki page.

    text (string) (optional). Text of the wiki page.

    comments (string) (optional). Comments of the wiki page.

    Returns True

    >>> redmine.wiki_page.update(Foo, project_id=vacation, title=FooBar, text=foo, comments=bar)True

    save

    redmine.resources.WikiPage.save()Saves the current state of a wiki page resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    >>> wiki_page = redmine.wiki_page.get(Foo, project_id=vacation)>>> wiki_page.title = Bar>>> wiki_page.text = bar>>> wiki_page.comments = changed foo to bar>>> wiki_page.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id, **params)Deletes single wiki page resource from the Redmine by its title.

    Parameters

    resource_id (string) (required). Title of the wiki page.

    project_id (integer or string) (required). Id or identifier of wiki pages project.

    Returns True

    >>> redmine.wiki_page.delete(Foo, project_id=1)True

    5.4.10 Query

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the query resource are provided via its manager. To get access to it you have to callredmine.query where redmine is a configured redmine object. See the Configuration about how to configureredmine object.

    48 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Create methods

    Not supported by Redmine

    Read methods

    get

    Not supported by Redmine

    all

    redmine.managers.ResourceManager.all(**params)Returns all query resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> queries = redmine.query.all(offset=10, limit=100)>>> queries

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    5.4.11 Attachment

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the attachment resource are provided via its manager. To get access to it you have to callredmine.attachment where redmine is a configured redmine object. See the Configuration about how toconfigure redmine object.

    5.4. Resources 49

  • Python Redmine Documentation, Release

    Create methods

    Not supported by Redmine. Some resources support adding attachments via its create/update methods, e.g. issue.

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single attachment resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the attachment.

    Returns Attachment resource object

    >>> attachment = redmine.attachment.get(76905)>>> attachment

    Hint: New in version 0.9.0.

    Attachment can be easily downloaded via the provided download() method which is a proxy to theredmine.download() method which provides several options to control the saving process (see docs for details):

    >>> attachment = redmine.attachment.get(76905)>>> filepath = attachment.download(savepath=/usr/local/, filename=image.jpg)>>> filepath/usr/local/image.jpg

    all

    Not supported by Redmine

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    50 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    5.4.12 Issue Status

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the issue status resource are provided via its manager. To get access to it you have to callredmine.issue_status where redmine is a configured redmine object. See the Configuration about howto configure redmine object.

    Create methods

    Not supported by Redmine

    Read methods

    get

    Not supported by Redmine

    all

    redmine.managers.ResourceManager.all()Returns all issue status resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> statuses = redmine.issue_status.all()>>> statuses

    Hint: New in version 1.0.0.

    IssueStatus resource object provides you with some relations. Relations are the other resource objects wrapped in aResourceSet which are somehow related to an IssueStatus resource object. The relations provided by the IssueStatusresource object are:

    issues

    >>> statuses = redmine.issue_status.all()>>> statuses[0]

    >>> statuses[0].issues

    5.4. Resources 51

  • Python Redmine Documentation, Release

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    5.4.13 Tracker

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the tracker resource are provided via its manager. To get access to it you have to callredmine.tracker where redmine is a configured redmine object. See the Configuration about how to con-figure redmine object.

    Create methods

    Not supported by Redmine

    Read methods

    get

    Not supported by Redmine

    all

    redmine.managers.ResourceManager.all()Returns all tracker resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> trackers = redmine.tracker.all()>>> trackers

    52 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Hint: New in version 1.0.0.

    Tracker resource object provides you with some relations. Relations are the other resource objects wrapped in aResourceSet which are somehow related to a Tracker resource object. The relations provided by the Tracker resourceobject are:

    issues

    >>> trackers = redmine.tracker.all()>>> trackers[0]

    >>> trackers[0].issues

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    5.4.14 Enumeration

    Supported by Redmine starting from version 2.2

    Manager

    All operations on the enumeration resource are provided via its manager. To get access to it you have to callredmine.enumeration where redmine is a configured redmine object. See the Configuration about how toconfigure redmine object.

    Create methods

    Not supported by Redmine

    5.4. Resources 53

  • Python Redmine Documentation, Release

    Read methods

    get

    Not supported by Redmine

    all

    Not supported by Redmine

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns enumeration resources that match the given lookup parameters.

    Parameters

    resource (string)

    issue_priorities

    time_entry_activities

    document_categories

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> enumerations = redmine.enumeration.filter(resource=time_entry_activities)>>> enumerations

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    5.4.15 Issue Category

    Supported by Redmine starting from version 1.3

    Manager

    All operations on the issue category resource are provided via its manager. To get access to it you have to callredmine.issue_category where redmine is a configured redmine object. See the Configuration about howto configure redmine object.

    54 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new issue category resource with given fields and saves it to the Redmine.

    Parameters

    project_id (integer or string) (required). Id or identifier of issue categorys project.

    name (string) (required). Issue category name.

    assigned_to_id (integer) (optional). The id of the user assigned to the category (newissues with this category will be assigned by default to this user).

    Returns IssueCategory resource object

    >>> category = redmine.issue_category.create(project_id=vacation, name=woohoo, assigned_to_id=13)>>> category

    new

    redmine.managers.ResourceManager.new()Creates new empty issue category resource but doesnt save it to the Redmine. This is useful if you want to setsome resource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributesare the same as for create method above.

    Returns IssueCategory resource object

    >>> category = redmine.issue_category.new()>>> category.project_id = vacation>>> category.name = woohoo>>> category.assigned_to_id = 13>>> category.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single issue category resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the issue category.

    Returns IssueCategory resource object

    >>> category = redmine.issue_category.get(794)>>> category

    all

    Not supported by Redmine

    5.4. Resources 55

  • Python Redmine Documentation, Release

    filter

    redmine.managers.ResourceManager.filter(**filters)Returns issue category resources that match the given lookup parameters.

    Parameters

    project_id (integer or string) (required). Get issue categories from the project with thegiven id, where id is either project id or project identifier.

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> categories = redmine.issue_category.filter(project_id=vacation)>>> categories

    Hint: You can also get issue categories from a project resource object directly using issue_categories relation:>>> project = redmine.project.get(vacation)>>> project.issue_categories

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of an issue category resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Issue category id.

    name (string) (optional). Issue category name.

    assigned_to_id (integer) (optional). The id of the user assigned to the category (newissues with this category will be assigned by default to this user).

    Returns True

    >>> redmine.issue_category.update(1, name=woohoo, assigned_to_id=13)True

    save

    redmine.resources.IssueCategory.save()Saves the current state of an issue category resource to the Redmine. Fields that can be changed are the same asfor update method above.

    Returns True

    56 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    >>> category = redmine.issue_category.get(1)>>> category.name = woohoo>>> category.assigned_to_id = 13>>> category.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id, **params)Deletes single issue category resource from the Redmine by its id.

    Parameters

    resource_id (integer) (required). Issue category id.

    reassign_to_id (integer) (optional). When there are issues assigned to the category youare deleting, this parameter lets you reassign these issues to the category with given id.

    Returns True

    >>> redmine.issue_category.delete(1, reassign_to_id=2)True

    5.4.16 Role

    Supported by Redmine starting from version 1.4

    Manager

    All operations on the role resource are provided via its manager. To get access to it you have to call redmine.rolewhere redmine is a configured redmine object. See the Configuration about how to configure redmine object.

    Create methods

    Not supported by Redmine

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id)Returns single role resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Id of the role.

    Returns Role resource object

    >>> role = redmine.role.get(4)>>> role

    5.4. Resources 57

  • Python Redmine Documentation, Release

    all

    redmine.managers.ResourceManager.all()Returns all role resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> roles = redmine.role.all()>>> roles

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    5.4.17 Group

    Supported by Redmine starting from version 2.1

    Manager

    All operations on the group resource are provided via its manager. To get access to it you have to callredmine.group where redmine is a configured redmine object. See the Configuration about how to configureredmine object.

    Create methods

    create

    redmine.managers.ResourceManager.create(**fields)Creates new group resource with given fields and saves it to the Redmine.

    Parameters

    name (string) (required). Group name.

    user_ids (list or tuple) (optional). Ids of users who will be members of a group.

    Returns Group resource object

    58 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    >>> group = redmine.group.create(name=Developers, user_ids=[13, 15, 25])>>> group

    new

    redmine.managers.ResourceManager.new()Creates new empty group resource but doesnt save it to the Redmine. This is useful if you want to set someresource fields later based on some condition(s) and only after that save it to the Redmine. Valid attributes arethe same as for create method above.

    Returns Group resource object

    >>> group = redmine.group.new()>>> group.name = Developers>>> group.user_ids = [13, 15, 25]>>> group.save()True

    Read methods

    get

    redmine.managers.ResourceManager.get(resource_id, **params)Returns single group resource from the Redmine by its id.

    Parameters

    resource_id (integer) (required). Id of the group.

    include (string)

    memberships

    users

    Returns Group resource object

    >>> group = redmine.group.get(524, include=memberships,users)>>> group

    Hint: New in version 0.4.0.

    Group resource object provides you with on demand includes. On demand includes are the other resource objectswrapped in a ResourceSet which are associated with a Group resource object. Keep in mind that on demand includesare retrieved in a separate request, that means that if the speed is important it is recommended to use get method witha include keyword argument. The on demand includes provided by the Group resource object are the same as inthe get method above:

    5.4. Resources 59

  • Python Redmine Documentation, Release

    >>> group = redmine.group.get(524)>>> group.users

    all

    redmine.managers.ResourceManager.all()Returns all group resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> groups = redmine.group.all()>>> groups

    filter

    Not supported by Redmine

    Update methods

    update

    redmine.managers.ResourceManager.update(resource_id, **fields)Updates values of given fields of a group resource and saves them to the Redmine.

    Parameters

    resource_id (integer) (required). Group id.

    name (string) (optional). Group name.

    user_ids (list or tuple) (optional). Ids of users who will be members of a group.

    Returns True

    >>> redmine.group.update(1, name=Developers, user_ids=[13, 15, 25])True

    save

    redmine.resources.Group.save()Saves the current state of a group resource to the Redmine. Fields that can be changed are the same as forupdate method above.

    Returns True

    60 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    >>> group = redmine.group.get(1)>>> group.name = Developers>>> group.user_ids = [13, 15, 25]>>> group.save()True

    Delete methods

    delete

    redmine.managers.ResourceManager.delete(resource_id)Deletes single group resource from the Redmine by its id.

    Parameters resource_id (integer) (required). Group id.

    Returns True

    >>> redmine.group.delete(1)True

    Users

    New in version 0.5.0.

    Python Redmine provides 2 methods to work with group users: add and remove.

    add

    redmine.resources.Group.User.add(user_id)Adds a user to a group by its id.

    Parameters user_id (integer) (required). User id.

    Returns True

    >>> group = redmine.group.get(1)>>> group.user.add(1)True

    remove

    redmine.resources.Group.User.remove(user_id)Removes a user from a group by its id.

    Parameters user_id (integer) (required). User id.

    Returns True

    >>> group = redmine.group.get(1)>>> group.user.remove(1)True

    5.4. Resources 61

  • Python Redmine Documentation, Release

    5.4.18 Custom Field

    Supported by Redmine starting from version 2.4

    Manager

    All operations on the custom field resource are provided via its manager. To get access to it you have to callredmine.custom_field where redmine is a configured redmine object. See the Configuration about howto configure redmine object.

    Create methods

    Not supported by Redmine

    Read methods

    get

    Not supported by Redmine

    all

    redmine.managers.ResourceManager.all()Returns all custom field resources from the Redmine.

    Parameters

    limit (integer) (optional). How much resources to return.

    offset (integer) (optional). Starting from what resource to return the other resources.

    Returns ResourceSet object

    >>> fields = redmine.custom_field.all()>>> fields

    filter

    Not supported by Redmine

    Update methods

    Not supported by Redmine

    Delete methods

    Not supported by Redmine

    62 Chapter 5. Table of contents

  • Python Redmine Documentation, Release

    5.4.19 Contact

    Supported starting from version 1.0.0 and only available if CRM plugin is installed.

    Hint: It is highly recommended to use CRM plugin 3.3.0 and higher because some bugs and inconsistencies in RESTAPI exists in older versions.

    Manager

    All operations on the contact resource are provided via its manager. To get access to it you have to callredmine.contact where redmine is a configured redmine object. See the Configuration about how to con-figure redmine obj