SDKs overview
Software Development Kits (SDKs) and client libraries for Bitbucket enable developers to programmatically interact with Bitbucket Cloud and Bitbucket Data Center instances. These tools abstract the underlying REST APIs, simplifying common operations such as managing repositories, configuring Bitbucket Pipelines, and handling pull requests or user permissions. Bitbucket offers official SDKs for key programming languages, supplemented by a range of community-contributed libraries that extend functionality or provide support for additional languages. Utilizing an SDK can significantly reduce development time by handling authentication, request formatting, and response parsing, allowing developers to focus on application logic. For detailed API specifications, consult the Bitbucket Cloud REST API reference.
The choice between an official SDK and a community library often depends on the specific project requirements, the desired level of support, and the language ecosystem. Official SDKs are typically maintained by Atlassian, ensuring compatibility with the latest API versions and adherence to best practices. Community libraries, while offering broader language support or specialized features, may have varying levels of maintenance and community backing. Bitbucket's extensibility also includes its add-on and integration framework, allowing for custom application development within the Bitbucket environment.
Official SDKs by language
Bitbucket provides official SDKs for several popular programming languages, designed to facilitate interaction with its API endpoints. These SDKs are maintained by Atlassian and offer a robust, supported method for integrating Bitbucket functionalities into applications.
| Language | Package/Library Name | Installation Method | Maturity |
|---|---|---|---|
| Python | atlassian-python-api |
pip install atlassian-python-api |
Stable |
| Java | bitbucket-rest-java-client (or direct REST calls) |
Maven/Gradle dependency | Stable |
| Node.js | bitbucket-api |
npm install bitbucket-api |
Stable |
The Python SDK, atlassian-python-api, is a comprehensive client for various Atlassian products, including Bitbucket. It abstracts API calls for repositories, pipelines, issues, and users, providing Pythonic methods for common operations. Java developers typically integrate with Bitbucket through direct REST API calls using HTTP client libraries or by leveraging a community-maintained client like bitbucket-rest-java-client, which simplifies the interaction. For Node.js, the bitbucket-api package offers asynchronous methods for interacting with the Bitbucket Cloud REST API, supporting promises and callbacks.
These official and widely-used libraries are documented to help developers get started quickly. For instance, the Bitbucket Cloud REST API introduction provides fundamental concepts necessary for using any of these SDKs effectively, including authentication mechanisms like OAuth 2.0 and App Passwords.
Installation
Installation procedures for Bitbucket SDKs vary by language ecosystem. Below are common methods for the officially supported and widely used community libraries.
Python
The atlassian-python-api library can be installed using pip, the standard package installer for Python:
pip install atlassian-python-api
After installation, you can import the library and instantiate the Bitbucket client. Ensure you have Python 3.6 or later for full compatibility. More details on the atlassian-python-api PyPI page are available, including specific version requirements and dependencies.
Java
For Java projects, if using a build automation tool like Maven or Gradle, you would add the dependency to your project's configuration file. For instance, using Maven:
<dependency>
<groupId>com.atlassian.bitbucket.cloud</groupId>
<artifactId>bitbucket-rest-java-client</artifactId>
<version>X.Y.Z</version> <!-- Replace with the latest version -->
</dependency>
Replace X.Y.Z with the latest stable version of the client library. Developers often find the Java HTTP Client documentation useful for making direct HTTP requests when a specific client library is not preferred or available for a particular API version.
Node.js
The bitbucket-api package is installed via npm, the Node.js package manager:
npm install bitbucket-api
This command adds the package to your project's node_modules directory and updates your package.json file. Node.js versions 12 and above are generally supported. For more information on Node.js package management, refer to the npm install documentation.
Quickstart example
This quickstart example demonstrates how to fetch a list of repositories from a Bitbucket workspace using the Python SDK. This approach applies to Bitbucket Cloud; for Bitbucket Data Center, the base URL and authentication methods might differ slightly.
Python Quickstart: List Repositories
First, ensure you have an App Password generated in your Bitbucket account settings with sufficient permissions (e.g., Repository > Read). You'll need your Bitbucket username and this App Password.
from atlassian import Bitbucket
import os
# Retrieve credentials from environment variables for security
BITBUCKET_USERNAME = os.environ.get('BITBUCKET_USERNAME')
BITBUCKET_APP_PASSWORD = os.environ.get('BITBUCKET_APP_PASSWORD')
BITBUCKET_WORKSPACE = 'your-workspace-id' # Replace with your Bitbucket workspace ID
if not BITBUCKET_USERNAME or not BITBUCKET_APP_PASSWORD:
print("Error: BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD environment variables must be set.")
exit(1)
# Initialize the Bitbucket client
# For Bitbucket Cloud, the base URL is typically 'https://api.bitbucket.org/2.0'
# For Bitbucket Data Center, it would be your instance's URL
bitbucket = Bitbucket(
url='https://api.bitbucket.org/2.0',
username=BITBUCKET_USERNAME,
password=BITBUCKET_APP_PASSWORD,
cloud=True # Specify True for Bitbucket Cloud
)
try:
# Fetch repositories for the specified workspace
# The 'workspace' parameter is crucial for Bitbucket Cloud API calls
repositories = bitbucket.get_all_repositories(workspace=BITBUCKET_WORKSPACE)
print(f"Repositories in workspace '{BITBUCKET_WORKSPACE}':")
for repo in repositories:
print(f"- {repo['name']} (UUID: {repo['uuid']})")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure your workspace ID is correct and the App Password has 'Repository > Read' permissions.")
This script initializes the Bitbucket client using environment variables for credentials, a recommended security practice. It then calls get_all_repositories, specifying the workspace ID, to retrieve and print the names and UUIDs of all repositories within that workspace. For creating an App Password in Bitbucket Cloud, refer to the official documentation on managing security settings.
Community libraries
Beyond the officially supported SDKs, the Bitbucket developer community has contributed a variety of libraries and tools that extend Bitbucket's functionality or offer support for additional programming languages. These libraries can be particularly useful for niche requirements or when integrating Bitbucket into environments where an official SDK is not available.
- Go: While no official Go SDK exists, repositories like
go-bitbucketon GitHub provide a client for the Bitbucket Cloud API. These community clients often mimic the structure of official SDKs, offering methods for common API interactions. - PHP: Developers working with PHP can find several community-maintained packages, such as
bitbucket-api-php, which allow for integration with Bitbucket's REST API. These typically handle OAuth authentication and provide object-oriented interfaces for API resources. - Ruby: For Ruby projects, libraries like
bitbucket_rest_apioffer a Ruby client for interacting with both Bitbucket Cloud and Data Center APIs. These libraries usually integrate with Ruby's HTTP client ecosystem. - CLI Tools: Various command-line interface (CLI) tools, often built on top of these community libraries, enable scriptable interactions with Bitbucket without writing extensive code. These can be useful for automation tasks in CI/CD pipelines or administrative scripts.
When using community libraries, it is important to assess their maintenance status, documentation quality, and community support. Reviewing the project's GitHub repository for recent commits, open issues, and pull requests can provide insight into its activity level. The Atlassian Developer Ecosystem page is a valuable resource for discovering community-contributed tools and understanding the broader integration landscape for Bitbucket.