A modern command-line interface for Bitbucket repositories
Project description
Bitbucket CLI
A modern, feature-rich command-line interface for interacting with Bitbucket repositories. Manage repositories, branches, commits, pipelines, and variables directly from your terminal.
โจ Features
- ๐ข Repository Management: List and explore repositories in workspaces
- ๐ฟ Branch Operations: View and manage repository branches
- ๐ Commit History: Browse commit history with detailed information
- ๐ Pipeline Control: List, monitor, and trigger Bitbucket Pipelines
- โ๏ธ Variable Management: Manage pipeline variables with secure handling
- ๐ Multiple Output Formats: Plain text and table formats
- ๐ Secure Authentication: App password-based authentication
- ๐ฏ Type-Safe: Written with modern Python type hints
- ๐ ๏ธ Error Handling: Comprehensive error handling and user-friendly messages
๐ Installation
From Source
git clone https://github.com/mdminhazulhaque/python-bitbucket-cli.git
cd python-bitbucket-cli
pip install -e .
From PyPI
pip install python-bitbucket-cli
๐ Authentication
The CLI uses Bitbucket App Passwords for authentication. Generate one from your Bitbucket Account Settings.
Required Permissions
Ensure your app password has the following permissions:
- โ Workspace โ Read
- โ Projects โ Read
- โ Repositories โ Read
- โ Pipelines โ Read, Write *(for triggering pipelines), Edit variables (for managing variables)
- โ Issues โ Read (optional, for future features)
- โ Pull requests โ Read (optional, for future features)
Environment Setup
Export your credentials as an environment variable:
export BITBUCKET_AUTH="username:app_password"
Add this to your shell profile (.bashrc, .zshrc, etc.) for persistence:
echo 'export BITBUCKET_AUTH="username:app_password"' >> ~/.zshrc
source ~/.zshrc
๐ Usage
The CLI provides several commands with consistent options and helpful output formatting.
Global Options
--help,-h: Show help message--version: Show version information
Command-Specific Options
Most commands support:
--table,-t: Display output in table format--workspace,-w: Specify Bitbucket workspace--repo,-r: Specify repository name
๐ Commands Reference
List Repositories
# List all repositories in a workspace
bitbucket-cli repos -w myworkspace
# Display in table format
bitbucket-cli repos -w myworkspace --table
Example Output:
frontend-v2
backend-api
mobile-app
documentation
infrastructure
List Branches
# List branches in a repository
bitbucket-cli branches -w myworkspace -r frontend-v2
# Table format
bitbucket-cli branches -w myworkspace -r frontend-v2 -t
Example Output:
master
develop
feature/user-auth
hotfix/login-bug
release/v2.1.0
List Commits
# List commits from master branch
bitbucket-cli commits -w myworkspace -r frontend-v2
# List commits from specific branch
bitbucket-cli commits -w myworkspace -r frontend-v2 -b develop
# Fetch all commits (not just first page)
bitbucket-cli commits -w myworkspace -r frontend-v2 --all
# Table format with detailed information
bitbucket-cli commits -w myworkspace -r frontend-v2 -t
Example Output:
bd4ed959 2024-12-21T11:58:13+00:00 John Doe Fix authentication bug
c0621052 2024-12-20T18:28:03+00:00 Jane Smith Add user dashboard
b60f0381 2024-12-19T01:09:36+00:00 Bob Wilson Update dependencies
List Pipeline Builds
# List recent pipeline builds
bitbucket-cli builds -w myworkspace -r frontend-v2
# List all builds
bitbucket-cli builds -w myworkspace -r frontend-v2 --all
# Table format
bitbucket-cli builds -w myworkspace -r frontend-v2 -t
Example Output:
42 2024-12-21T03:56:07.704Z master John Doe SUCCESSFUL
41 2024-12-20T06:19:35.715Z develop Jane Smith FAILED
40 2024-12-19T01:52:33.846Z feature/auth Bob Wilson SUCCESSFUL
Trigger Pipelines
# Trigger pipeline on a branch
bitbucket-cli trigger -w myworkspace -r frontend-v2 -b master
# Trigger custom pipeline on specific commit
bitbucket-cli trigger -w myworkspace -r frontend-v2 -b master \
-c bd4ed959e90944d8f661de57d314dd8eacd5e79e \
-p deploy-production
Example Output:
โ
Pipeline 43 started successfully!
๐ View progress: https://bitbucket.org/myworkspace/frontend-v2/addon/pipelines/home#!/results/43
Manage Variables
# List all variables
bitbucket-cli variables -w myworkspace -r frontend-v2
# List in table format
bitbucket-cli variables -w myworkspace -r frontend-v2 -t
# Create a new variable
bitbucket-cli variables -w myworkspace -r frontend-v2 \
--create -k API_KEY -v "your-api-key-here"
# Create a secured variable
bitbucket-cli variables -w myworkspace -r frontend-v2 \
--create -k SECRET_TOKEN -v "super-secret-token" --secured
# Delete a variable (use the UUID from list command)
bitbucket-cli variables -w myworkspace -r frontend-v2 \
--delete "{8cc198d9-44ff-43ea-9473-acd697bcbf31}"
Example Output:
{8cc198d9-44ff-43ea-9473-acd697bcbf31} API_KEY your-api-key-here ๐
{9f06955b-3ca9-4b93-908f-fe353977ec48} SECRET_TOKEN ******************** ๐
{18643776-dbe1-4fe6-b01b-6d103242c9ca} ENVIRONMENT production ๐
๐ง Advanced Usage
Using Short Alias
The installation provides a short bb alias for convenience:
bb repos -w myworkspace
bb builds -w myworkspace -r myapp -t
bb trigger -w myworkspace -r myapp -b master
Combining with Other Tools
# Count repositories
bb repos -w myworkspace | wc -l
# Find specific branch
bb branches -w myworkspace -r myapp | grep feature
# Get latest commit hash
bb commits -w myworkspace -r myapp | head -1 | cut -d' ' -f1
# Monitor pipeline status
watch -n 30 'bb builds -w myworkspace -r myapp | head -5'
Scripting and Automation
#!/bin/bash
# Deploy script example
WORKSPACE="mycompany"
REPO="production-api"
BRANCH="master"
echo "๐ Starting deployment for $REPO..."
# Trigger deployment pipeline
RESULT=$(bb trigger -w $WORKSPACE -r $REPO -b $BRANCH -p deploy-production)
if [[ $RESULT == *"started successfully"* ]]; then
echo "โ
Deployment initiated successfully"
echo "$RESULT"
else
echo "โ Deployment failed to start"
exit 1
fi
๐ ๏ธ Development
Setup Development Environment
git clone https://github.com/mdminhazulhaque/python-bitbucket-cli.git
cd python-bitbucket-cli
# Install the package
make install
Project Structure
python-bitbucket-cli/
โโโ bitbucket/
โ โโโ __init__.py
โ โโโ bitbucket.py # Core API client
โ โโโ main.py # CLI interface
โโโ requirements.txt
โโโ setup.py
โโโ Makefile
โโโ LICENSE
โโโ README.md
API Client Architecture
The BitBucketClient class provides a clean, type-safe interface to the Bitbucket REST API:
- Error Handling: Custom exceptions with clear error messages
- Type Safety: Full type hints for better development experience
- Session Management: Reuses HTTP connections for better performance
- Pagination: Automatic handling of paginated API responses
- Authentication: Secure app password authentication
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with Click for the CLI interface
- Uses Requests for HTTP client functionality
- Table formatting powered by Tabulate
- Inspired by the need for efficient DevOps workflows
๐ Support
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: mdminhazulhaque@gmail.com
๐บ๏ธ Roadmap
- Pull request operations (create, list, approve, merge)
- Issue management (create, list, update)
- Project management (create, list, update)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_bitbucket_cli-1.4.0.tar.gz.
File metadata
- Download URL: python_bitbucket_cli-1.4.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d76193159dd41e29c2c78c261017c79c3a249a0efe9ef9e838976bddb7226e40
|
|
| MD5 |
d1e36200a618f249099417a78dc0df26
|
|
| BLAKE2b-256 |
b93979be8f8c5b8b3f18daa2ddf882c89e58db6e8a98d50330dcf54cae0ea351
|
Provenance
The following attestation bundles were made for python_bitbucket_cli-1.4.0.tar.gz:
Publisher:
pypi.yml on mdminhazulhaque/python-bitbucket-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_bitbucket_cli-1.4.0.tar.gz -
Subject digest:
d76193159dd41e29c2c78c261017c79c3a249a0efe9ef9e838976bddb7226e40 - Sigstore transparency entry: 238825759
- Sigstore integration time:
-
Permalink:
mdminhazulhaque/python-bitbucket-cli@c59ea7b64a480f68df7f68704eb6a43acd5327da -
Branch / Tag:
refs/heads/master - Owner: https://github.com/mdminhazulhaque
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c59ea7b64a480f68df7f68704eb6a43acd5327da -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_bitbucket_cli-1.4.0-py3-none-any.whl.
File metadata
- Download URL: python_bitbucket_cli-1.4.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d324ed33294606ac38aab21eb7fc3db904ffa18531f6b123bb4427dc43fe3c5
|
|
| MD5 |
a73d000b2c1ade61e8ebdb31a53191bc
|
|
| BLAKE2b-256 |
df6a9f77967845aec97c234fb87257dad56301179ff51094d3be832abb5daec2
|
Provenance
The following attestation bundles were made for python_bitbucket_cli-1.4.0-py3-none-any.whl:
Publisher:
pypi.yml on mdminhazulhaque/python-bitbucket-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_bitbucket_cli-1.4.0-py3-none-any.whl -
Subject digest:
9d324ed33294606ac38aab21eb7fc3db904ffa18531f6b123bb4427dc43fe3c5 - Sigstore transparency entry: 238825761
- Sigstore integration time:
-
Permalink:
mdminhazulhaque/python-bitbucket-cli@c59ea7b64a480f68df7f68704eb6a43acd5327da -
Branch / Tag:
refs/heads/master - Owner: https://github.com/mdminhazulhaque
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@c59ea7b64a480f68df7f68704eb6a43acd5327da -
Trigger Event:
push
-
Statement type: