Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
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: :code:pip install pybitbucket
.. image:: https://img.shields.io/pypi/v/pybitbucket.svg :target: https://pypi.python.org/pypi/pybitbucket/0.12.0
.. image:: https://img.shields.io/pypi/status/pybitbucket.svg :target: https://pypi.python.org/pypi/pybitbucket
.. image:: https://img.shields.io/pypi/pyversions/pybitbucket.svg :target: https://pypi.python.org/pypi/pybitbucket
.. image:: https://img.shields.io/pypi/l/pybitbucket.svg :target: https://bitbucket.org/atlassian/python-bitbucket/src/master/LICENSE.txt
.. image:: https://img.shields.io/pypi/dm/pybitbucket.svg :target: https://pypi.python.org/pypi/pybitbucket
The :code:Authenticator
subclasses prepare API requests with credentials.
The simplest case is :code:Anonymous
which connects with no credentials.
:code:Anonymous
can be used with an publicly available resources.
For private resources,
:code: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 :code: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 <https://confluence.atlassian.com/bitbucket/two-step-verification-777023203.html>
,
then you will need to use an app password <https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication#app-pw>
with the :code:BasicAuthenticator
,
not your regular user password.
The :code: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 :code:obtain_authorization()
and perhaps may need to use a different grant types.
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:
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:
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.
For example, to list the commits for a snippet:
::
snip = Snippet.find_snippet_by_id("Xqoz8", bitbucket)
for commit in snip.commits():
print(commit)
What relationships 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.relationships())
Just like attributes, the relationships for the same resource may change depending on how you got to it.
If you need the canonical resource with all attributes, use the :code:self()
relationship:
::
snips = Snippet.find_snippets_for_role(client=bitbucket)
one_snip = next(snips) # one_snip has no files relationship in this context.
real_snip = next(one_snip.self())
print(real_snip.files)
It's not virtual like a virtual machine. More like a specialized container for a Python version and libraries.
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.pip install --upgrade --no-use-wheel setuptools
pip install --upgrade --no-use-wheel pip
pip install virtualenvwrapper
virtual environment <http://docs.python-guide.org/en/latest/dev/virtualenvs/>
_: :code:mkvirtualenv python-bitbucket
Once created, use :code:workon python-bitbucket
to restore the virtual environment.pip install -r requirements-dev.txt
Loads required libraries into the virtual environment.paver test_all
Run all the unit tests and analyze the source code.PUT
and :code:DELETE
for :code:snippet.watch
from snippets Endpoint <https://confluence.atlassian.com/display/BITBUCKET/snippets+endpoint>
_.version 1 endpoints <https://confluence.atlassian.com/display/BITBUCKET/Version+1>
_ for:
FAQs
A Python wrapper for the Bitbucket API
We found that pybitbucket37 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.