Atlassian Python API Wrapper
The `atlassian-python-api` library provides a comprehensive and convenient Python wrapper for interacting with various Atlassian products, including Jira, Confluence, Bitbucket, Crowd, Service Desk, Xray, and Bamboo. It supports both Atlassian Cloud and Server/Data Center instances by leveraging their official REST APIs, along with some additional private methods and protocols. Currently at version 4.0.7, the library maintains an active development and release cadence, frequently adding new features, bug fixes, and adjustments for evolving Atlassian APIs.
Common errors
-
requests.exceptions.HTTPError: 401 Client Error
cause This error occurs when authentication credentials are incorrect or missing.fixEnsure that the correct username and password or API token are provided when initializing the Confluence object. -
SyntaxError: invalid syntax
cause This error occurs when using Python 2.x, as the atlassian-python-api library requires Python 3.x.fixUpgrade to Python 3.x to use the atlassian-python-api library. -
ImportError: cannot import name 'bitbucket' from 'atlassian'
cause This error occurs when the atlassian-python-api library is not installed or not properly installed.fixInstall the atlassian-python-api library using pip: pip install atlassian-python-api. -
AttributeError: module 'atlassian' has no attribute 'Jira'
cause This error occurs when the atlassian-python-api library is not installed or not properly installed.fixInstall the atlassian-python-api library using pip: pip install atlassian-python-api. -
ModuleNotFoundError: No module named 'atlassian'
cause This error occurs when the atlassian-python-api library is not installed.fixInstall the atlassian-python-api library using pip: pip install atlassian-python-api.
Warnings
- breaking Version 4.0.0 removed Python 2 support. Projects using `atlassian-python-api` with Python 2 will break upon upgrade.
- breaking Atlassian Cloud APIs no longer support basic authentication with a username and password (deprecated since June 2019). Attempting to use a password for Cloud authentication will result in an 'invalid credentials' error.
- gotcha There are significant API and authentication differences between Atlassian Cloud and Server/Data Center instances. This includes authentication methods (API Token for Cloud vs. username/password/PAT for Server) and content ID formats (UUID strings for Cloud vs. numeric IDs for Server).
- gotcha The `attach_file()` method in Confluence may not create a new revision when re-uploading a file with the same name, potentially leading to errors. Additionally, `download_attachments_from_page` in version 4.0.0 started returning bytes instead of text, which might require changes in how file content is handled.
- deprecated Atlassian itself is deprecating some Jira JQL search API endpoints (effective May 1, 2025). While `atlassian-python-api` has updated to support the new `search/jql` endpoint, older scripts or direct API calls might be affected.
- gotcha Installation may fail with a 'subprocess-exited-with-error' and 'krb5-config: not found' if a transitive dependency attempts to build components requiring Kerberos development headers. This often occurs in minimal environments like `python:*-slim` Docker images.
- gotcha When attempting to install `gssapi` (often a dependency for Kerberos authentication with Atlassian Server/Data Center instances), the build process may fail on minimal Linux distributions (like Alpine Linux) due to missing Kerberos development libraries.
Install
-
pip install atlassian-python-api -
pip install atlassian-python-api[kerberos]
Imports
- Jira
from atlassian import Jira
- Confluence
from atlassian import Confluence
- Bitbucket
from atlassian import Bitbucket
- Jira
from atlassian.jira import Jira
from atlassian.jira import JiraCloud
Quickstart
import os
from atlassian import Jira
# For Jira Cloud, use API Token authentication.
# Generate an API token at: https://id.atlassian.com/manage-profile/security/api-tokens
JIRA_URL = os.environ.get('ATLASSIAN_JIRA_URL', 'https://your-domain.atlassian.net')
JIRA_EMAIL = os.environ.get('ATLASSIAN_JIRA_EMAIL', 'your_email@example.com')
JIRA_API_TOKEN = os.environ.get('ATLASSIAN_JIRA_API_TOKEN', 'YOUR_API_TOKEN')
if not all([JIRA_URL, JIRA_EMAIL, JIRA_API_TOKEN]):
print("Please set ATLASSIAN_JIRA_URL, ATLASSIAN_JIRA_EMAIL, and ATLASSIAN_JIRA_API_TOKEN environment variables.")
else:
try:
jira = Jira(
url=JIRA_URL,
username=JIRA_EMAIL,
password=JIRA_API_TOKEN, # API token for Cloud
cloud=True # Important for Jira Cloud
)
# Test connection by getting current user
current_user = jira.myself()
print(f"Successfully connected to Jira. Current user: {current_user['displayName']}")
# Example: Get all projects
projects = jira.get_all_projects(start=0, limit=5)
print(f"First 5 projects: {[p['name'] for p in projects]}")
except Exception as e:
print(f"Error connecting to Jira or fetching data: {e}")