SDKs overview
Software Development Kits (SDKs) and client libraries for the Bitbucket API streamline interactions with Bitbucket Cloud, enabling programmatic access to its features for repository management, pull request workflows, user administration, and CI/CD pipeline automation. These tools encapsulate the underlying HTTP requests and JSON response parsing, presenting developers with language-native objects and methods. This abstraction reduces the boilerplate code required to integrate Bitbucket functionalities into custom applications, scripts, and services.
The Bitbucket API follows a RESTful architecture, making it accessible via standard HTTP methods. However, SDKs provide convenience by handling authentication flows, error handling, and data serialization/deserialization. This means developers do not need to manually construct API endpoint URLs, manage request headers, or parse raw JSON responses, which significantly accelerates development cycles.
While Atlassian provides official SDKs for specific languages, the developer community also contributes a range of third-party libraries. These community-driven projects often extend functionality, support additional languages, or offer different paradigms for API interaction. When selecting an SDK, developers typically consider factors such as language compatibility, library maturity, active maintenance, and the specific features supported, as outlined in the Bitbucket API reference documentation.
Official SDKs by language
Atlassian maintains official SDKs for key programming languages, ensuring direct support and alignment with the latest Bitbucket API specifications. These libraries are designed to provide a robust and reliable interface for developers building integrations with Bitbucket Cloud. The primary official SDKs focus on Java and Python, reflecting their prevalence in enterprise development and scripting environments.
These official SDKs are typically hosted on their respective language-specific package managers and often include comprehensive documentation that mirrors the structure of the main Bitbucket API documentation, helping developers understand how to map API concepts to library methods. Using official SDKs generally offers benefits such as direct support from Atlassian, adherence to API best practices, and timely updates when the Bitbucket API evolves.
Official SDKs table
| Language | Package/Module | Install Command | Maturity |
|---|---|---|---|
| Python | bitbucket-python |
pip install bitbucket-python |
Stable, Actively Maintained |
| Java | bitbucket-java-client (via Maven/Gradle) |
(See Maven/Gradle config) | Stable, Actively Maintained |
For Java, the client is typically included as a dependency in your project's pom.xml (Maven) or build.gradle (Gradle) file. For example, a Maven dependency entry would look like this, though specific versions should be checked against the official Bitbucket API documentation for the latest stable release:
<dependency>
<groupId>com.atlassian.bitbucket.cloud</groupId>
<artifactId>bitbucket-java-client</artifactId>
<version>2.x.x</version>
</dependency>
Installation
Installing Bitbucket API SDKs typically involves using the package manager specific to your chosen programming language. The process is generally straightforward, requiring a single command to add the library to your project's dependencies.
Python SDK Installation
The official Python SDK, bitbucket-python, can be installed using pip, the Python package installer. It is recommended to install it within a virtual environment to manage project dependencies effectively. For detailed instructions on creating and activating virtual environments, consult the Python venv module documentation.
# Create a virtual environment
python3 -m venv bitbucket_env
# Activate the virtual environment
source bitbucket_env/bin/activate
# Install the Bitbucket Python SDK
pip install bitbucket-python
After installation, you can import the library into your Python scripts and begin interacting with the Bitbucket API.
Java SDK Installation (Maven)
For Java projects, the Bitbucket Java client is usually managed via build automation tools like Maven or Gradle. Here's how to add it as a dependency in a Maven project's pom.xml file. Always verify the latest stable version on the Bitbucket API overview page or Maven Central.
<dependencies>
<dependency>
<groupId>com.atlassian.bitbucket.cloud</groupId&n>
<artifactId>bitbucket-java-client</artifactId>
<version>2.1.0</version> <!-- Replace with the latest version -->
</dependency>
</dependencies>
Once added, your build tool will automatically download and include the library when you build your project.
Quickstart example
This quickstart example demonstrates how to use the official Python SDK to list repositories for a specific Bitbucket workspace. Before running this code, ensure you have an App password configured in your Bitbucket account with appropriate permissions (e.g., 'Repositories' -> 'Read'). For details on generating app passwords, refer to the Bitbucket API authentication guide.
First, set your Bitbucket username and App password as environment variables or replace the placeholders directly (though environment variables are recommended for security).
from bitbucket.bitbucket import Bitbucket
import os
# --- Configuration ---
# Replace with your Bitbucket username and App Password
# It's recommended to use environment variables for credentials
USERNAME = os.environ.get('BITBUCKET_USERNAME', 'YOUR_BITBUCKET_USERNAME')
APP_PASSWORD = os.environ.get('BITBUCKET_APP_PASSWORD', 'YOUR_BITBUCKET_APP_PASSWORD')
WORKSPACE = 'YOUR_WORKSPACE_SLUG' # e.g., 'my-team-workspace'
# Ensure credentials are set
if USERNAME == 'YOUR_BITBUCKET_USERNAME' or APP_PASSWORD == 'YOUR_BITBUCKET_APP_PASSWORD':
print("Error: Please set BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD environment variables or replace placeholders.")
exit(1)
# --- Initialize the Bitbucket client ---
# The Bitbucket client handles authentication automatically with username and app password
client = Bitbucket(USERNAME, APP_PASSWORD, WORKSPACE)
# --- List repositories ---
try:
print(f"Listing repositories for workspace: {WORKSPACE}")
# The 'repositories' object provides methods to interact with repository API endpoints
response = client.repositories.all(workspace=WORKSPACE)
# The 'response' object often contains a 'json()' method to get the parsed data
repositories_data = response.json()
if repositories_data and 'values' in repositories_data:
for repo in repositories_data['values']:
print(f" - Name: {repo['name']}, Full Name: {repo['full_name']}")
else:
print("No repositories found or unexpected response structure.")
except Exception as e:
print(f"An error occurred: {e}")
# In a real application, you'd add more specific error handling based on API response codes
This script initializes the Bitbucket client with your credentials and then calls the repositories.all() method to fetch a list of all repositories within the specified workspace. The response is then parsed to extract and print the name and full name of each repository. Remember that the WORKSPACE slug is the identifier found in the URL of your Bitbucket workspace (e.g., bitbucket.org/<WORKSPACE_SLUG>/).
Community libraries
Beyond the official offerings, the Bitbucket API benefits from a vibrant developer community that contributes a range of third-party libraries and tools. These community-maintained projects often fill gaps in language support, offer alternative programming paradigms, or provide specialized functionalities. While not officially supported by Atlassian, many of these libraries are well-regarded and actively maintained.
Developers frequently turn to community libraries for languages such as Node.js, Go, and PHP, where official SDKs might not be available or as feature-rich. These libraries can be found on platforms like GitHub, npm (for Node.js), or Packagist (for PHP).
Examples of notable community libraries (non-exhaustive):
- Node.js: Projects like
bitbucket-apiornode-bitbucketare often available via npm. They typically offer promise-based interfaces for asynchronous API calls, which is common in Node.js development. For instance, a Node.js library might expose methods likebitbucket.repositories.get({ owner, repo_slug }). - Go: While less common for extensive SDKs, Go developers often use generic HTTP clients combined with JSON unmarshaling to interact with the Bitbucket API directly, or they might find smaller, purpose-built wrappers for specific API endpoints.
- PHP: Libraries such as
bitbucket-php-client(or similar names) can be found on Packagist and integrated via Composer. These typically provide an object-oriented interface for making API requests and handling responses in a PHP-native way.
When considering a community library, it is crucial to evaluate its maintenance status, the number of contributors, recent commit history, and the clarity of its documentation. Checking the issue tracker and pull request activity on the project's repository (e.g., GitHub) can provide insights into its health and responsiveness. Additionally, ensuring compatibility with the latest version of the Bitbucket REST API v2 is essential for stable integrations. Community support forums like those on Stack Overflow with the bitbucket-api tag can also offer valuable guidance and troubleshooting assistance for these libraries.