File size: 6,242 Bytes
56d74b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
.. Atlassian Python API documentation master file, created by
   sphinx-quickstart on Thu Sep 13 13:43:20 2018.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Atlassian Python API's documentation!
================================================
|Build Status| |PyPI version| |PyPI Downloads| |License| |Codacy Badge| |Docs|

Getting started
---------------

Install package using pip:

``pip install atlassian-python-api``

Add a connection:

.. code-block:: python

    from atlassian import Jira
    from atlassian import Confluence
    from atlassian import Bitbucket
    from atlassian import ServiceDesk
    from atlassian import Xray

    jira = Jira(
        url='http://localhost:8080',
        username='admin',
        password='admin')

    confluence = Confluence(
        url='http://localhost:8090',
        username='admin',
        password='admin')

    bitbucket = Bitbucket(
        url='http://localhost:7990',
        username='admin',
        password='admin')

    service_desk = ServiceDesk(
        url='http://localhost:8080',
        username='admin',
        password='admin')

    xray = Xray(
        url='http://localhost:8080',
        username='admin',
        password='admin')

Other authentication methods
----------------------------

Further authentication methods are available. For example OAuth can be used:

.. code-block:: python

    oauth_dict = {
        'access_token': 'access_token',
        'access_token_secret': 'access_token_secret',
        'consumer_key': 'consumer_key',
        'key_cert': 'key_cert'}

    jira = Jira(
        url='http://localhost:8080',
        oauth=oauth_dict)

    confluence = Confluence(
        url='http://localhost:8090',
        oauth=oauth_dict)

    bitbucket = Bitbucket(
        url='http://localhost:7990',
        oauth=oauth_dict)

    service_desk = ServiceDesk(
        url='http://localhost:8080',
        oauth=oauth_dict)

    xray = Xray(
        url='http://localhost:8080',
        oauth=oauth_dict)

OAuth 2.0 is also supported:

.. code-block:: python

    from atlassian.bitbucket import Cloud

    # token is a dictionary and must at least contain "access_token"
    # and "token_type".
    oauth2_dict = {
        "client_id": client_id,
        "token": token}

    bitbucket_cloud = Cloud(
        oauth2=oauth2_dict)

    # For a detailed example see bitbucket_oauth2.py in
    # examples/bitbucket


Or Kerberos *(installation with kerberos extra necessary)*:

.. code-block:: python

    jira = Jira(
        url='http://localhost:8080',
        kerberos={})

    confluence = Confluence(
        url='http://localhost:8090',
        kerberos={})

    bitbucket = Bitbucket(
        url='http://localhost:7990',
        kerberos={})

    service_desk = ServiceDesk(
        url='http://localhost:8080',
        kerberos={})

    xray = Xray(
        url='http://localhost:8080',
        kerberos={})

Or reuse cookie file:

.. code-block:: python

    from atlassian import utils
    cookie_dict = utils.parse_cookie_file("cookie.txt")

    jira = Jira(
        url='http://localhost:8080',
        cookies=cookie_dict)

    confluence = Confluence(
        url='http://localhost:8090',
        cookies=cookie_dict)

    bitbucket = Bitbucket(
        url='http://localhost:7990',
        cookies=cookie_dict)

    service_desk = ServiceDesk(
        url='http://localhost:8080',
        cookies=cookie_dict)

    xray = Xray(
        url='http://localhost:8080',
        cookies=cookie_dict)

To authenticate to the Atlassian Cloud APIs Jira, Confluence, ServiceDesk:

.. code-block:: python

    # Obtain an API token from: https://id.atlassian.com/manage-profile/security/api-tokens
    # You cannot log-in with your regular password to these services.

    jira = Jira(
        url='https://your-domain.atlassian.net',
        username=jira_username,
        password=jira_api_token,
        cloud=True)

    confluence = Confluence(
        url='https://your-domain.atlassian.net',
        username=jira_username,
        password=jira_api_token,
        cloud=True)

    service_desk = ServiceDesk(
        url='https://your-domain.atlassian.net',
        username=jira_username,
        password=jira_api_token,
        cloud=True)

And to Bitbucket Cloud:

.. code-block:: python

    # Log-in with E-Mail / Username and regular password
    # or with Username and App password.
    # Get App password from https://bitbucket.org/account/settings/app-passwords/.
    # Log-in with E-Mail and App password not possible.
    # Username can be found here: https://bitbucket.org/account/settings/

    from atlassian.bitbucket import Cloud

    bitbucket = Cloud(
        username=bitbucket_email,
        password=bitbucket_password,
        cloud=True)

    bitbucket_app_pw = Cloud(
        username=bitbucket_username,
        password=bitbucket_app_password,
        cloud=True)

.. toctree::
   :maxdepth: 2

   jira
   confluence
   bitbucket
   bamboo
   service_desk
   xray

.. |Build Status| image:: https://github.com/atlassian-api/atlassian-python-api/workflows/Test/badge.svg?branch=master
   :target: https://pypi.python.org/pypi/atlassian-python-api
   :alt: Build status
.. |PyPI version| image:: https://badge.fury.io/py/atlassian-python-api.svg
   :target: https://badge.fury.io/py/atlassian-python-api
   :alt: PyPI version
.. |License| image:: https://img.shields.io/pypi/l/atlassian-python-api.svg
   :target: https://pypi.python.org/pypi/atlassian-python-api
   :alt: License
.. |Codacy Badge| image:: https://api.codacy.com/project/badge/Grade/c822908f507544fe98ae37b25518ae3d
   :target: https://www.codacy.com/project/gonchik/atlassian-python-api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AstroMatt/atlassian-python-api&utm_campaign=Badge_Grade_Dashboard
   :alt: Codacy Badge
.. |PyPI Downloads| image:: https://pepy.tech/badge/atlassian-python-api/month
   :alt: PyPI Downloads
.. |Docs| image:: https://readthedocs.org/projects/atlassian-python-api/badge/?version=latest
   :target: https://atlassian-python-api.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status