Skip to main content

Fork of a Python wrapper for the Bitbucket API

Project description

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_fork

https://img.shields.io/pypi/v/pybitbucket_fork.svg https://img.shields.io/pypi/status/pybitbucket_fork.svg https://img.shields.io/pypi/pyversions/pybitbucket_fork.svg https://img.shields.io/pypi/l/pybitbucket_fork.svg https://img.shields.io/pypi/dm/pybitbucket_fork.svg

This is a fork of pybitbucket <https://bitbucket.org/atlassian/python-bitbucket>.

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.

  1. brew install python This 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.

  2. pip install --upgrade --no-use-wheel setuptools

  3. pip install --upgrade --no-use-wheel pip

  4. pip install virtualenvwrapper

Project Setup

  1. Clone the repository and set it as the current working directory.

  2. (Optional, but good practice) Create a virtual environment: mkvirtualenv python-bitbucket Once created, use workon python-bitbucket to restore the virtual environment.

  3. pip install -r requirements-dev.txt Loads required libraries into the virtual environment.

  4. paver test_all Run all the unit tests and analyze the source code.

TODO

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybitbucket_fork-0.12.2.tar.gz (85.8 kB view details)

Uploaded Source

Built Distribution

pybitbucket_fork-0.12.2-py3.6.egg (76.6 kB view details)

Uploaded Source

File details

Details for the file pybitbucket_fork-0.12.2.tar.gz.

File metadata

File hashes

Hashes for pybitbucket_fork-0.12.2.tar.gz
Algorithm Hash digest
SHA256 6b1571b8386791039f38849fa96880ec6ff91ad5d47133cb93b36ee092e49431
MD5 902a9d41ae86ec1dde0f21f082991edf
BLAKE2b-256 796b013c6b59a84d4b49628d0e869151c60d9f68edfd722cf03639aaf62bbfe3

See more details on using hashes here.

File details

Details for the file pybitbucket_fork-0.12.2-py3.6.egg.

File metadata

File hashes

Hashes for pybitbucket_fork-0.12.2-py3.6.egg
Algorithm Hash digest
SHA256 08d0fcf86955f630f9b4ea310d317138cac7a191e65135f7c3ab56cd1025a6c0
MD5 cf4d6d410b7c8f28c6a1e0f69d841b22
BLAKE2b-256 4230bbb0b00e7c84d793e34fdb79c4ac246c9758cdcf6ec56aba3cec07963608

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page