A Python wrapper for the Bitbucket Cloud REST API.
This is not known to work with Bitbucket Server,
previously known as Stash.
To start working with this library, just do: pip install pybitbucket
Adopting this library
Authenticate
The Authenticator subclasses prepare API requests with credentials.
The simplest case is Anonymous which connects with no credentials.
Anonymous can be used with an publicly available resources.
For private resources,
BasicAuthenticator uses email, username, and password as credentials.
If your client application has it’s own mechanisms for working with these values,
you can subclass the BasicAuthenticator to provide custom behavior.
To “plug in” your implementation or a standard one, just do:
bitbucket = Client(
BasicAuthenticator(
'your_username_here',
'your_secret_password_here',
'pybitbucket@mailinator.com'))
If you have enabled two-step verification,
then you will need to use an app password with the BasicAuthenticator,
not your regular user password.
The OAuth2Authenticator is intended as an example and superclass.
It may work for some command-line clients.
Other clients like web applications
will need an appropriate implementation of obtain_authorization()
and perhaps may need to use a different grant types.
Find Things
For example, to find all your snippets:
for snip in Snippet.find_snippets_for_role(client=bitbucket):
print(snip)
The method says “for role” but, if not provided, it will use the default of owner. Hence, all your snippets.
In general, finding things is done with a static find method on each type of resource. If the resource is plural, like “snippets” above, then the find method is a generator. You can use it with iterators or comprehensions. The resources you can find are:
user and team
repository and snippet
pull request and comment
commit and build status
hook and branch restriction
Create Things
For example, to create a new snippet:
snip = Snippet.create(
files=open_files(["README.rst"]),
payload=SnippetPayload().add_title("My New Snippet"),
client=bitbucket)
The resources you can create are:
repository and snippet
pull request and comment
build status
hook and branch restriction
Examine Things
For example, to examine attributes on a snippet:
snip = Snippet.find_snippet_by_id("Xqoz8", bitbucket)
s = '\n'.join([
"id : {}".format(snip.id),
"is_private : {}".format(snip.is_private),
"title : {}".format(snip.title),
"files : {}".format(snip.filenames),
"created_on : {}".format(snip.created_on),
"updated_on : {}".format(snip.updated_on),
"scm : {}".format(snip.scm),
]) if snip else 'Snippet not found.'
print(s)
What attributes are available? You will not find them hardcoded in Python. They are populated dynamically from the JSON response. You can query the list via a convenience method:
snip = Snippet.find_snippet_by_id("Xqoz8", bitbucket)
print(snip.attributes())
Beware. The attributes for the same resource may change depending on how you got to it.
Developing
Python Virtual Environment Setup (for OS X)
It’s not virtual like a virtual machine. More like a specialized container for a Python version and libraries.
brew install pythonThis installs the latest version of Python 2.7 with a version of setuptools and pip. Unfortunately, those versions of setuptools and pip seem to be broken.pip install --upgrade --no-use-wheel setuptoolspip install --upgrade --no-use-wheel pippip install virtualenvwrapper
Project Setup
Clone the repository and set it as the current working directory.
(Optional, but good practice) Create a virtual environment:
mkvirtualenv python-bitbucketOnce created, useworkon python-bitbucketto restore the virtual environment.pip install -r requirements-dev.txtLoads required libraries into the virtual environment.paver test_allRun all the unit tests and analyze the source code.
TODO
PUTandDELETEforsnippet.watchfrom snippets Endpoint.- Wrap the version 1 endpoints for:
groups
group-privileges
invitations
Metadata
Release files for pybitbucket37 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pybitbucket37-0.0.2.tar.gz | 81.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pybitbucket37-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 115.7 kB
Release files / pybitbucket37-0.0.2.tar.gz
| Download URL | pybitbucket37-0.0.2.tar.gz |
|---|---|
| Size | 81.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d00deab2f883b4db7da87d612e7c79c1c73fa6dda58b45c8875174acf9edec5
|
|
BLAKE2b-256 checksum How to use checksums |
b9be2dab112b4e92e4aa2d25c8a304976d34dcb7367777c9eaa542a17346871a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2
|
Release files / pybitbucket37-0.0.2-py3-none-any.whl
| Download URL | pybitbucket37-0.0.2-py3-none-any.whl |
|---|---|
| Size | 34.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84e302633d6bc6dad3b6be54982e2eb3d3ebc020f60347f96a9f331127dbd1f3
|
|
BLAKE2b-256 checksum How to use checksums |
47b6dafa8ef7c9e87e3074f43d2e57af6385818d99d529e2a6d33c167fbf2315
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2
|
Security for pybitbucket37 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.