├── .gitignore ├── DCO ├── LICENSE ├── NOTICE ├── README.md ├── bitbucket ├── __init__.py ├── accounts.py ├── changesets.py ├── client.py ├── deploykeys.py ├── links.py ├── namespace.py ├── repositories.py ├── repository.py ├── services.py ├── toplevel.py ├── urls.py └── webhooks.py ├── code-of-conduct.md ├── example.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | -------------------------------------------------------------------------------- /DCO: -------------------------------------------------------------------------------- 1 | Developer Certificate of Origin 2 | Version 1.1 3 | 4 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 5 | 660 York Street, Suite 102, 6 | San Francisco, CA 94110 USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | 12 | Developer's Certificate of Origin 1.1 13 | 14 | By making a contribution to this project, I certify that: 15 | 16 | (a) The contribution was created in whole or in part by me and I 17 | have the right to submit it under the open source license 18 | indicated in the file; or 19 | 20 | (b) The contribution is based upon previous work that, to the best 21 | of my knowledge, is covered under an appropriate open source 22 | license and I have the right under that license to submit that 23 | work with modifications, whether created in whole or in part 24 | by me, under the same open source license (unless I am 25 | permitted to submit under a different license), as indicated 26 | in the file; or 27 | 28 | (c) The contribution was provided directly to me by some other 29 | person who certified (a), (b) or (c) and I have not modified 30 | it. 31 | 32 | (d) I understand and agree that this project and the contribution 33 | are public and that a record of the contribution (including all 34 | personal information I submit with it, including my sign-off) is 35 | maintained indefinitely and may be redistributed consistent with 36 | this project or the open source license(s) involved. 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | CoreOS Project 2 | Copyright 2018 CoreOS, Inc 3 | 4 | This product includes software developed at CoreOS, Inc. 5 | (http://www.coreos.com/). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # py-bitbucket 2 | Python library for working with the BitBucket V1 and V2 APIs via OAuth. `dispatch` method is loosely based 3 | on the method found in https://github.com/Sheeprider/BitBucket-api -------------------------------------------------------------------------------- /bitbucket/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python library for working with BitBucket API V1. 3 | """ 4 | 5 | from bitbucket.toplevel import BitBucket 6 | -------------------------------------------------------------------------------- /bitbucket/accounts.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with the accounts API. """ 2 | 3 | from bitbucket.urls import account_profile_url 4 | 5 | class BitBucketAccountsClient(object): 6 | """ A client for talking to the BitBucket accounts API. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | 12 | def get_profile(self, accountname_or_email): 13 | """ Returns profile information for the account matching the given account name or email 14 | address. 15 | """ 16 | url = account_profile_url(accountname_or_email) 17 | return self._dispatcher.dispatch(url, access_token=self._access_token, 18 | access_token_secret=self._access_token_secret) 19 | -------------------------------------------------------------------------------- /bitbucket/changesets.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository's change set. """ 2 | 3 | from bitbucket.urls import repository_changesets_url, repository_changeset_url 4 | 5 | class BitBucketRepositoryChangeSetsClient(object): 6 | """ Client class representing the changesets under a repository in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | self._repository_name = repository_name 13 | 14 | @property 15 | def namespace(self): 16 | """ Returns the namespace. """ 17 | return self._namespace 18 | 19 | @property 20 | def repository_name(self): 21 | """ Returns the repository name. """ 22 | return self._repository_name 23 | 24 | def list(self, start, limit=50): 25 | """ Returns a list of the change sets found under the repository. """ 26 | url = repository_changesets_url(self._namespace, self._repository_name) 27 | return self._dispatcher.dispatch(url, access_token=self._access_token, 28 | access_token_secret=self._access_token_secret, 29 | params={'start': start, 'limit': limit}) 30 | 31 | def get(self, node_id): 32 | """ Returns the contents of the specified changeset. """ 33 | url = repository_changeset_url(self._namespace, self._repository_name, node_id) 34 | return self._dispatcher.dispatch(url, access_token=self._access_token, 35 | access_token_secret=self._access_token_secret) 36 | -------------------------------------------------------------------------------- /bitbucket/client.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with BitBucket with a set of auth credentials. """ 2 | 3 | from bitbucket.urls import current_user_url, current_user_repos_url 4 | from bitbucket.namespace import BitBucketNamespaceClient 5 | from bitbucket.accounts import BitBucketAccountsClient 6 | 7 | class BitBucketClient(object): 8 | """ A client for talking to the BitBucket API. """ 9 | def __init__(self, dispatcher, access_token, access_token_secret): 10 | self._dispatcher = dispatcher 11 | self._access_token = access_token 12 | self._access_token_secret = access_token_secret 13 | 14 | def get_current_user(self): 15 | """ Returns information about the authorized user. """ 16 | url = current_user_url() 17 | return self._dispatcher.dispatch(url, access_token=self._access_token, 18 | access_token_secret=self._access_token_secret) 19 | 20 | def get_visible_repositories(self): 21 | """ Returns a list of all repositories visible to the authorized user. """ 22 | url = current_user_repos_url() 23 | return self._dispatcher.dispatch(url, access_token=self._access_token, 24 | access_token_secret=self._access_token_secret) 25 | 26 | def for_namespace(self, namespace): 27 | """ Returns a client for accessing information for the given user or team. """ 28 | return BitBucketNamespaceClient(self._dispatcher, self._access_token, self._access_token_secret, 29 | namespace) 30 | 31 | def accounts(self): 32 | """ Returns a client for accessing account information. """ 33 | return BitBucketAccountsClient(self._dispatcher, self._access_token, self._access_token_secret) 34 | -------------------------------------------------------------------------------- /bitbucket/deploykeys.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository's deploy keys. """ 2 | 3 | from bitbucket.urls import repository_deploy_keys_url, repository_deploy_key_url 4 | 5 | class BitBucketRepositoryDeployKeysClient(object): 6 | """ Client class representing the deploy keys under a repository in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | self._repository_name = repository_name 13 | 14 | @property 15 | def namespace(self): 16 | """ Returns the namespace. """ 17 | return self._namespace 18 | 19 | @property 20 | def repository_name(self): 21 | """ Returns the repository name. """ 22 | return self._repository_name 23 | 24 | def all(self): 25 | """ Returns a list of the deploy keys found under the repository. """ 26 | url = repository_deploy_keys_url(self._namespace, self._repository_name) 27 | return self._dispatcher.dispatch(url, access_token=self._access_token, 28 | access_token_secret=self._access_token_secret) 29 | 30 | def get(self, key_id): 31 | """ Returns the contents of the specified deploy key. """ 32 | url = repository_deploy_key_url(self._namespace, self._repository_name, key_id) 33 | return self._dispatcher.dispatch(url, access_token=self._access_token, 34 | access_token_secret=self._access_token_secret) 35 | 36 | def delete(self, key_id): 37 | """ Deletes the specified deploy key. """ 38 | url = repository_deploy_key_url(self._namespace, self._repository_name, key_id) 39 | return self._dispatcher.dispatch(url, method='DELETE', access_token=self._access_token, 40 | access_token_secret=self._access_token_secret) 41 | 42 | def create(self, label, contents): 43 | """ Creates a new deploy key. """ 44 | url = repository_deploy_keys_url(self._namespace, self._repository_name) 45 | return self._dispatcher.dispatch(url, method='POST', access_token=self._access_token, 46 | access_token_secret=self._access_token_secret, 47 | label=label, key=contents) 48 | -------------------------------------------------------------------------------- /bitbucket/links.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository's links. """ 2 | 3 | from bitbucket.urls import repository_links_url, repository_link_url 4 | 5 | class BitBucketRepositoryLinksClient(object): 6 | """ Client class representing the links under a repository in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | self._repository_name = repository_name 13 | 14 | @property 15 | def namespace(self): 16 | """ Returns the namespace. """ 17 | return self._namespace 18 | 19 | @property 20 | def repository_name(self): 21 | """ Returns the repository name. """ 22 | return self._repository_name 23 | 24 | def all(self): 25 | """ Returns a list of the links found under the repository. """ 26 | url = repository_links_url(self._namespace, self._repository_name) 27 | return self._dispatcher.dispatch(url, access_token=self._access_token, 28 | access_token_secret=self._access_token_secret) 29 | 30 | def get(self, link_id): 31 | """ Returns the contents of the specified link. """ 32 | url = repository_link_url(self._namespace, self._repository_name, link_id) 33 | return self._dispatcher.dispatch(url, access_token=self._access_token, 34 | access_token_secret=self._access_token_secret) 35 | 36 | def delete(self, link_id): 37 | """ Deletes the specified link. """ 38 | url = repository_link_url(self._namespace, self._repository_name, link_id) 39 | return self._dispatcher.dispatch(url, method='DELETE', access_token=self._access_token, 40 | access_token_secret=self._access_token_secret) 41 | 42 | def create(self, handler, link_url, link_key): 43 | """ Creates a new link. """ 44 | url = repository_links_url(self._namespace, self._repository_name) 45 | return self._dispatcher.dispatch(url, method='POST', access_token=self._access_token, 46 | access_token_secret=self._access_token_secret, 47 | handler=handler, link_url=link_url, link_key=link_key) 48 | -------------------------------------------------------------------------------- /bitbucket/namespace.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a BitBucket namespace. """ 2 | 3 | from bitbucket.repositories import BitBucketRepositoriesClient 4 | 5 | class BitBucketNamespaceClient(object): 6 | """ Client class representing a single namespace in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | 13 | @property 14 | def namespace(self): 15 | """ Returns the namespace. """ 16 | return self._namespace 17 | 18 | def repositories(self): 19 | """ Returns access to the namespace's repositories. """ 20 | return BitBucketRepositoriesClient(self._dispatcher, self._access_token, 21 | self._access_token_secret, self._namespace) -------------------------------------------------------------------------------- /bitbucket/repositories.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with BitBucket repositories. """ 2 | 3 | from bitbucket.repository import BitBucketRepositoryClient 4 | 5 | class BitBucketRepositoriesClient(object): 6 | """ Client class representing the repositories under a namespace in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | 13 | @property 14 | def namespace(self): 15 | """ Returns the namespace. """ 16 | return self._namespace 17 | 18 | def get(self, repository_name): 19 | """ Returns a client for interacting with a specific repository. """ 20 | return BitBucketRepositoryClient(self._dispatcher, self._access_token, 21 | self._access_token_secret, self._namespace, 22 | repository_name) -------------------------------------------------------------------------------- /bitbucket/repository.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository. """ 2 | 3 | from bitbucket.urls import (repository_branches_url, repository_tags_url, repository_branches_tags_url, 4 | repository_manifest_url, repository_path_contents_url, 5 | repository_path_raw_contents_url, repository_main_branch_url, 6 | repository_branch_url, repository_tag_url) 7 | 8 | from bitbucket.deploykeys import BitBucketRepositoryDeployKeysClient 9 | from bitbucket.links import BitBucketRepositoryLinksClient 10 | from bitbucket.services import BitBucketRepositoryServicesClient 11 | from bitbucket.changesets import BitBucketRepositoryChangeSetsClient 12 | from bitbucket.webhooks import BitBucketRepositoryWebhooksClient 13 | 14 | class BitBucketRepositoryClient(object): 15 | """ Client class representing a repository in bitbucket. """ 16 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 17 | self._dispatcher = dispatcher 18 | self._access_token = access_token 19 | self._access_token_secret = access_token_secret 20 | self._namespace = namespace 21 | self._repository_name = repository_name 22 | 23 | @property 24 | def namespace(self): 25 | """ Returns the namespace. """ 26 | return self._namespace 27 | 28 | @property 29 | def repository_name(self): 30 | """ Returns the repository name. """ 31 | return self._repository_name 32 | 33 | def changesets(self): 34 | """ Returns a resource for managing the changesets under this repository. """ 35 | return BitBucketRepositoryChangeSetsClient(self._dispatcher, self._access_token, 36 | self._access_token_secret, self._namespace, 37 | self._repository_name) 38 | 39 | def webhooks(self): 40 | """ Returns a resource for managing the webhooks under this repository. """ 41 | return BitBucketRepositoryWebhooksClient(self._dispatcher, self._access_token, 42 | self._access_token_secret, self._namespace, 43 | self._repository_name) 44 | 45 | def services(self): 46 | """ Returns a resource for managing the services under this repository. """ 47 | return BitBucketRepositoryServicesClient(self._dispatcher, self._access_token, 48 | self._access_token_secret, self._namespace, 49 | self._repository_name) 50 | 51 | def links(self): 52 | """ Returns a resource for managing the links under this repository. """ 53 | return BitBucketRepositoryLinksClient(self._dispatcher, self._access_token, 54 | self._access_token_secret, self._namespace, 55 | self._repository_name) 56 | 57 | def deploykeys(self): 58 | """ Returns a resource for managing the deploy keys under this repository. """ 59 | return BitBucketRepositoryDeployKeysClient(self._dispatcher, self._access_token, 60 | self._access_token_secret, self._namespace, 61 | self._repository_name) 62 | 63 | def get_main_branch(self): 64 | """ Returns the main branch for this repository. """ 65 | url = repository_main_branch_url(self._namespace, self._repository_name) 66 | return self._dispatcher.dispatch(url, access_token=self._access_token, 67 | access_token_secret=self._access_token_secret) 68 | 69 | def get_branches(self): 70 | """ Returns the list of branches in this repository. """ 71 | url = repository_branches_url(self._namespace, self._repository_name) 72 | return self._dispatcher.dispatch(url, access_token=self._access_token, 73 | access_token_secret=self._access_token_secret) 74 | 75 | def get_tags(self): 76 | """ Returns the list of tags in this repository. """ 77 | url = repository_tags_url(self._namespace, self._repository_name) 78 | return self._dispatcher.dispatch(url, access_token=self._access_token, 79 | access_token_secret=self._access_token_secret) 80 | 81 | def get_branches_and_tags(self): 82 | """ Returns the list of branches and tags in this repository. """ 83 | url = repository_branches_tags_url(self._namespace, self._repository_name) 84 | return self._dispatcher.dispatch(url, access_token=self._access_token, 85 | access_token_secret=self._access_token_secret) 86 | 87 | def get_manifest(self, revision='default'): 88 | """ Returns the manifest for the repository. """ 89 | url = repository_manifest_url(self._namespace, self._repository_name, revision) 90 | return self._dispatcher.dispatch(url, access_token=self._access_token, 91 | access_token_secret=self._access_token_secret) 92 | 93 | def get_path_contents(self, path, revision='default'): 94 | """ Returns the contents of the given path. If the path ends in a /, it is treated as a 95 | directory and the contents of the directory are returned. 96 | """ 97 | url = repository_path_contents_url(self._namespace, self._repository_name, revision, path) 98 | return self._dispatcher.dispatch(url, access_token=self._access_token, 99 | access_token_secret=self._access_token_secret) 100 | 101 | def get_raw_path_contents(self, path, revision='default'): 102 | """ Returns the raw contents of the given path. If the path ends in a /, it is treated as a 103 | directory and the contents of the directory are returned. 104 | """ 105 | url = repository_path_raw_contents_url(self._namespace, self._repository_name, revision, path) 106 | return self._dispatcher.dispatch(url, access_token=self._access_token, 107 | access_token_secret=self._access_token_secret) 108 | 109 | def get_branch(self, branch_name): 110 | """ Returns information about the branch with the specified name under this repository, if any. 111 | """ 112 | url = repository_branch_url(self._namespace, self._repository_name, branch_name) 113 | return self._dispatcher.dispatch(url, access_token=self._access_token, 114 | access_token_secret=self._access_token_secret) 115 | 116 | def get_tag(self, tag_name): 117 | """ Returns information about the tag with the specified name under this repository, if any. 118 | """ 119 | url = repository_tag_url(self._namespace, self._repository_name, tag_name) 120 | return self._dispatcher.dispatch(url, access_token=self._access_token, 121 | access_token_secret=self._access_token_secret) 122 | -------------------------------------------------------------------------------- /bitbucket/services.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository's services. """ 2 | 3 | from bitbucket.urls import repository_services_url, repository_service_url 4 | 5 | class BitBucketRepositoryServicesClient(object): 6 | """ Client class representing the services under a repository in bitbucket. """ 7 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 8 | self._dispatcher = dispatcher 9 | self._access_token = access_token 10 | self._access_token_secret = access_token_secret 11 | self._namespace = namespace 12 | self._repository_name = repository_name 13 | 14 | @property 15 | def namespace(self): 16 | """ Returns the namespace. """ 17 | return self._namespace 18 | 19 | @property 20 | def repository_name(self): 21 | """ Returns the repository name. """ 22 | return self._repository_name 23 | 24 | def all(self): 25 | """ Returns a list of the services found under the repository. """ 26 | url = repository_services_url(self._namespace, self._repository_name) 27 | return self._dispatcher.dispatch(url, access_token=self._access_token, 28 | access_token_secret=self._access_token_secret) 29 | 30 | def get(self, service_id): 31 | """ Returns the contents of the specified service. """ 32 | url = repository_service_url(self._namespace, self._repository_name, service_id) 33 | return self._dispatcher.dispatch(url, access_token=self._access_token, 34 | access_token_secret=self._access_token_secret) 35 | 36 | def delete(self, service_id): 37 | """ Deletes the specified service. """ 38 | url = repository_service_url(self._namespace, self._repository_name, service_id) 39 | return self._dispatcher.dispatch(url, method='DELETE', access_token=self._access_token, 40 | access_token_secret=self._access_token_secret) 41 | 42 | def create(self, type, **kwargs): 43 | """ Creates a new service. """ 44 | url = repository_services_url(self._namespace, self._repository_name) 45 | return self._dispatcher.dispatch(url, method='POST', access_token=self._access_token, 46 | access_token_secret=self._access_token_secret, 47 | type=type, **kwargs) 48 | -------------------------------------------------------------------------------- /bitbucket/toplevel.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from requests import Request, Session 3 | from requests_oauthlib import OAuth1 4 | 5 | import requests 6 | import requests.exceptions 7 | import json 8 | 9 | try: 10 | from urlparse import parse_qs 11 | except ImportError: 12 | from urllib.parse import parse_qs 13 | 14 | from bitbucket.urls import request_token_url, authenticate_url, access_token_url 15 | from bitbucket.client import BitBucketClient 16 | 17 | 18 | class BitBucket(object): 19 | """ This is the main class for interacting with the BitBucket API (V1). """ 20 | def __init__(self, consumer_key, consumer_secret, callback_url, timeout=None): 21 | self._consumer_key = consumer_key 22 | self._consumer_secret = consumer_secret 23 | self._callback_url = callback_url 24 | self._timeout = timeout 25 | 26 | def get_authorized_client(self, access_token, access_token_secret): 27 | """ Returns a client for talking to an authorized endpoint. """ 28 | return BitBucketClient(self, access_token, access_token_secret) 29 | 30 | 31 | def dispatch(self, api_url, access_token, access_token_secret, method='GET', params=None, 32 | json_body=False, **kwargs): 33 | """ Dispatches a signed request to the given URL, with the given access token and secret. """ 34 | oauth = OAuth1(self._consumer_key, client_secret=self._consumer_secret, 35 | resource_owner_key=access_token, resource_owner_secret=access_token_secret) 36 | 37 | data = kwargs 38 | headers = {} 39 | 40 | if json_body: 41 | headers['Content-Type'] = 'application/json' 42 | data = json.dumps(data) 43 | 44 | session = Session() 45 | request = Request(method=method, url=api_url, auth=oauth, params=params, data=data, 46 | headers=headers) 47 | 48 | try: 49 | response = session.send(request.prepare(), timeout=self._timeout) 50 | except requests.exceptions.ReadTimeout: 51 | return (False, None, 'Timeout when contacting BitBucket') 52 | except requests.exceptions.RequestException as rex: 53 | return (False, None, 'Exception when contacting BitBucket: %s' % rex.message) 54 | 55 | status_code = response.status_code 56 | text = response.text 57 | error = response.reason 58 | 59 | # 200-299: OK. 60 | if status_code / 100 == 2: 61 | try: 62 | return (True, json.loads(text or ''), None) 63 | except TypeError: 64 | pass 65 | except ValueError: 66 | pass 67 | 68 | return (True, text, None) 69 | 70 | return (False, None, error or 'Error: %s' % status_code) 71 | 72 | 73 | def _get_request_token(self): 74 | """ Retrieves a request token from the BitBucket API endpoint. Returns a tuple containing 75 | whether the operation succeeded and the request token or error encountered. 76 | """ 77 | oauth = OAuth1(self._consumer_key, client_secret=self._consumer_secret, 78 | callback_uri=self._callback_url) 79 | 80 | request = requests.post(request_token_url(), auth=oauth, timeout=self._timeout) 81 | if request.status_code == 200: 82 | credentials = parse_qs(request.content) 83 | token = (credentials.get('oauth_token')[0], credentials.get('oauth_token_secret')[0]) 84 | return (True, token, None) 85 | 86 | return (False, None, request.content) 87 | 88 | 89 | def get_authorization_url(self): 90 | """ Returns the URL for requesting OAuth authorization for the client, along with the 91 | access token and access token secret for the authorization. Note that the access 92 | token and secret will be needed again for the verify step, so they must be saved 93 | somewhere. """ 94 | (status, token, error) = self._get_request_token() 95 | if not status: 96 | return (False, None, error) 97 | 98 | data = { 99 | 'url': authenticate_url(token[0]), 100 | 'access_token': token[0], 101 | 'access_token_secret': token[1] 102 | } 103 | 104 | return (True, data, None) 105 | 106 | 107 | def verify_token(self, access_token, access_token_secret, verifier): 108 | """ Exchanges the verifier for a new access token and secret which can be used to make 109 | requests. 110 | """ 111 | oauth = OAuth1(self._consumer_key, client_secret=self._consumer_secret, 112 | resource_owner_key=access_token, resource_owner_secret=access_token_secret, 113 | verifier=verifier) 114 | 115 | try: 116 | request = requests.post(access_token_url(), auth=oauth, timeout=self._timeout) 117 | except requests.exceptions.ReadTimeout: 118 | return (False, None, 'Timeout when contacting BitBucket') 119 | except requests.exceptions.RequestException as rex: 120 | return (False, None, 'Exception when contacting BitBucket: %s' % rex.message) 121 | 122 | if request.status_code == 200: 123 | credentials = parse_qs(request.content) 124 | token = (credentials.get('oauth_token')[0], credentials.get('oauth_token_secret')[0]) 125 | return (True, token, None) 126 | 127 | return (False, None, request.content) 128 | 129 | -------------------------------------------------------------------------------- /bitbucket/urls.py: -------------------------------------------------------------------------------- 1 | _BASE_URL_V1 = 'https://bitbucket.org/!api/1.0/%s' 2 | _BASE_URL_V2 = 'https://api.bitbucket.org/2.0/%s' 3 | 4 | def request_token_url(): 5 | """ URL for getting a request token. """ 6 | return _BASE_URL_V1 % 'oauth/request_token/' 7 | 8 | def authenticate_url(token): 9 | """ URL for performing authentication on behalf of a user. """ 10 | return _BASE_URL_V1 % ('oauth/authenticate?oauth_token=%s' % token) 11 | 12 | def access_token_url(): 13 | """ URL for exchanging a verifier for an access token. """ 14 | return _BASE_URL_V1 % 'oauth/access_token/' 15 | 16 | def current_user_url(): 17 | """ URL for retrieving the current authorized user. """ 18 | return _BASE_URL_V1 % 'user' 19 | 20 | def current_user_repos_url(): 21 | """ URL for retrieving the repositories viewable by the current user. """ 22 | return _BASE_URL_V1 % 'user/repositories' 23 | 24 | def repository_branches_url(namespace, repository): 25 | """ URL for retrieiving the branches under a repository. """ 26 | return _BASE_URL_V1 % ('repositories/%s/%s/branches' % (namespace, repository)) 27 | 28 | def repository_tags_url(namespace, repository): 29 | """ URL for retrieiving the tags under a repository. """ 30 | return _BASE_URL_V1 % ('repositories/%s/%s/tags' % (namespace, repository)) 31 | 32 | def repository_branches_tags_url(namespace, repository): 33 | """ URL for retrieiving the branches and tags under a repository. """ 34 | return _BASE_URL_V1 % ('repositories/%s/%s/branches-tags' % (namespace, repository)) 35 | 36 | def repository_manifest_url(namespace, repository, revision): 37 | """ URL for retrieving a manifest of a revision of a repository. """ 38 | return _BASE_URL_V1 % ('repositories/%s/%s/manifest/%s' % (namespace, repository, revision)) 39 | 40 | def repository_path_contents_url(namespace, repository, revision, path): 41 | """ Returns the contents of the path (file or directory) under a repository. """ 42 | return _BASE_URL_V1 % ('repositories/%s/%s/src/%s/%s' % (namespace, repository, revision, path)) 43 | 44 | def repository_path_raw_contents_url(namespace, repository, revision, path): 45 | """ Returns the contents of the path (file or directory) under a repository. """ 46 | return _BASE_URL_V1 % ('repositories/%s/%s/raw/%s/%s' % (namespace, repository, revision, path)) 47 | 48 | def repository_deploy_keys_url(namespace, repository): 49 | """ Returns the list of deploy keys in a repository. """ 50 | return _BASE_URL_V1 % ('repositories/%s/%s/deploy-keys' % (namespace, repository)) 51 | 52 | def repository_deploy_key_url(namespace, repository, key_id): 53 | """ Returns the contents of a deploy key under a repository. """ 54 | return _BASE_URL_V1 % ('repositories/%s/%s/deploy-keys/%s' % (namespace, repository, key_id)) 55 | 56 | def repository_links_url(namespace, repository): 57 | """ Returns the list of links in a repository. """ 58 | return _BASE_URL_V1 % ('repositories/%s/%s/links' % (namespace, repository)) 59 | 60 | def repository_link_url(namespace, repository, link_id): 61 | """ Returns the contents of a link under a repository. """ 62 | return _BASE_URL_V1 % ('repositories/%s/%s/links/%s' % (namespace, repository, link_id)) 63 | 64 | def repository_services_url(namespace, repository): 65 | """ Returns the list of services in a repository. """ 66 | return _BASE_URL_V1 % ('repositories/%s/%s/services' % (namespace, repository)) 67 | 68 | def repository_service_url(namespace, repository, service_id): 69 | """ Returns the contents of a service under a repository. """ 70 | return _BASE_URL_V1 % ('repositories/%s/%s/services/%s' % (namespace, repository, service_id)) 71 | 72 | def repository_main_branch_url(namespace, repository): 73 | """ Returns the name of the main branch for the repository. """ 74 | return _BASE_URL_V1 % ('repositories/%s/%s/main-branch' % (namespace, repository)) 75 | 76 | def repository_changesets_url(namespace, repository): 77 | """ Returns the list of changesets in a repository. """ 78 | return _BASE_URL_V1 % ('repositories/%s/%s/changesets' % (namespace, repository)) 79 | 80 | def repository_changeset_url(namespace, repository, node_id): 81 | """ Returns the contents of a changeset under a repository. """ 82 | return _BASE_URL_V1 % ('repositories/%s/%s/changesets/%s' % (namespace, repository, node_id)) 83 | 84 | def account_profile_url(accountname): 85 | """ Returns the account profile information for the given account. """ 86 | return _BASE_URL_V1 % ('users/%s' % accountname) 87 | 88 | def repository_webhooks_url(namespace, repository): 89 | """ Returns the list of webhooks in a repository. """ 90 | return _BASE_URL_V2 % ('repositories/%s/%s/hooks' % (namespace, repository)) 91 | 92 | def repository_webhook_url(namespace, repository, service_id): 93 | """ Returns the contents of a webhook under a repository. """ 94 | return _BASE_URL_V2 % ('repositories/%s/%s/hooks/%s' % (namespace, repository, service_id)) 95 | 96 | def repository_branch_url(namespace, repository, branch_name): 97 | """ URL for retrieiving a specific branch under a repository. """ 98 | return _BASE_URL_V2 % ('repositories/%s/%s/refs/branches/%s' % (namespace, repository, 99 | branch_name)) 100 | def repository_tag_url(namespace, repository, tag_name): 101 | """ URL for retrieiving a specific tag under a repository. """ 102 | return _BASE_URL_V2 % ('repositories/%s/%s/refs/tags/%s' % (namespace, repository, tag_name)) 103 | 104 | -------------------------------------------------------------------------------- /bitbucket/webhooks.py: -------------------------------------------------------------------------------- 1 | """ Defines a client class for working with a specific BitBucket repository's webhooks 2 | as defined in API v2: https://confluence.atlassian.com/display/BITBUCKET/webhooks+Resource. """ 3 | 4 | from bitbucket.urls import repository_webhooks_url, repository_webhook_url 5 | 6 | class BitBucketRepositoryWebhooksClient(object): 7 | """ Client class representing the webhooks under a repository in bitbucket. """ 8 | def __init__(self, dispatcher, access_token, access_token_secret, namespace, repository_name): 9 | self._dispatcher = dispatcher 10 | self._access_token = access_token 11 | self._access_token_secret = access_token_secret 12 | self._namespace = namespace 13 | self._repository_name = repository_name 14 | 15 | @property 16 | def namespace(self): 17 | """ Returns the namespace. """ 18 | return self._namespace 19 | 20 | @property 21 | def repository_name(self): 22 | """ Returns the repository name. """ 23 | return self._repository_name 24 | 25 | def all(self): 26 | """ Returns a list of the webhooks found under the repository. """ 27 | url = repository_webhooks_url(self._namespace, self._repository_name) 28 | return self._dispatcher.dispatch(url, access_token=self._access_token, 29 | access_token_secret=self._access_token_secret) 30 | 31 | def get(self, uuid): 32 | """ Returns the contents of the specified webhook. """ 33 | url = repository_webhook_url(self._namespace, self._repository_name, uuid) 34 | return self._dispatcher.dispatch(url, access_token=self._access_token, 35 | access_token_secret=self._access_token_secret) 36 | 37 | def delete(self, uuid): 38 | """ Deletes the specified webhook. """ 39 | url = repository_webhook_url(self._namespace, self._repository_name, uuid) 40 | return self._dispatcher.dispatch(url, method='DELETE', access_token=self._access_token, 41 | access_token_secret=self._access_token_secret) 42 | 43 | def update(self, uuid, description, hook_url, events, active=True): 44 | """ Updates an existing webhook. """ 45 | url = repository_webhook_url(self._namespace, self._repository_name, uuid) 46 | data = { 47 | 'description': description, 48 | 'url': hook_url, 49 | 'active': active, 50 | 'events': events 51 | } 52 | 53 | return self._dispatcher.dispatch(url, method='PUT', access_token=self._access_token, 54 | access_token_secret=self._access_token_secret, json_body=True, 55 | **data) 56 | 57 | def create(self, description, hook_url, events, active=True, skip_cert_verification=False): 58 | """ Creates a new webhook. """ 59 | url = repository_webhooks_url(self._namespace, self._repository_name) 60 | data = { 61 | 'description': description, 62 | 'url': hook_url, 63 | 'active': active, 64 | 'events': events, 65 | 'skip_cert_verification': skip_cert_verification, 66 | } 67 | 68 | return self._dispatcher.dispatch(url, method='POST', access_token=self._access_token, 69 | access_token_secret=self._access_token_secret, json_body=True, 70 | **data) 71 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | ## CoreOS Community Code of Conduct 2 | 3 | ### Contributor Code of Conduct 4 | 5 | As contributors and maintainers of this project, and in the interest of 6 | fostering an open and welcoming community, we pledge to respect all people who 7 | contribute through reporting issues, posting feature requests, updating 8 | documentation, submitting pull requests or patches, and other activities. 9 | 10 | We are committed to making participation in this project a harassment-free 11 | experience for everyone, regardless of level of experience, gender, gender 12 | identity and expression, sexual orientation, disability, personal appearance, 13 | body size, race, ethnicity, age, religion, or nationality. 14 | 15 | Examples of unacceptable behavior by participants include: 16 | 17 | * The use of sexualized language or imagery 18 | * Personal attacks 19 | * Trolling or insulting/derogatory comments 20 | * Public or private harassment 21 | * Publishing others' private information, such as physical or electronic addresses, without explicit permission 22 | * Other unethical or unprofessional conduct. 23 | 24 | Project maintainers have the right and responsibility to remove, edit, or 25 | reject comments, commits, code, wiki edits, issues, and other contributions 26 | that are not aligned to this Code of Conduct. By adopting this Code of Conduct, 27 | project maintainers commit themselves to fairly and consistently applying these 28 | principles to every aspect of managing this project. Project maintainers who do 29 | not follow or enforce the Code of Conduct may be permanently removed from the 30 | project team. 31 | 32 | This code of conduct applies both within project spaces and in public spaces 33 | when an individual is representing the project or its community. 34 | 35 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 36 | reported by contacting a project maintainer, Brandon Philips 37 | , and/or Rithu John . 38 | 39 | This Code of Conduct is adapted from the Contributor Covenant 40 | (http://contributor-covenant.org), version 1.2.0, available at 41 | http://contributor-covenant.org/version/1/2/0/ 42 | 43 | ### CoreOS Events Code of Conduct 44 | 45 | CoreOS events are working conferences intended for professional networking and 46 | collaboration in the CoreOS community. Attendees are expected to behave 47 | according to professional standards and in accordance with their employer’s 48 | policies on appropriate workplace behavior. 49 | 50 | While at CoreOS events or related social networking opportunities, attendees 51 | should not engage in discriminatory or offensive speech or actions including 52 | but not limited to gender, sexuality, race, age, disability, or religion. 53 | Speakers should be especially aware of these concerns. 54 | 55 | CoreOS does not condone any statements by speakers contrary to these standards. 56 | CoreOS reserves the right to deny entrance and/or eject from an event (without 57 | refund) any individual found to be engaging in discriminatory or offensive 58 | speech or actions. 59 | 60 | Please bring any concerns to the immediate attention of designated on-site 61 | staff, Brandon Philips , and/or Rithu John . 62 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | from bitbucket import BitBucket 2 | 3 | def example(): 4 | consumer_key = raw_input('Enter your consumer key: ') 5 | consumer_secret = raw_input('Enter your consumer secret: ') 6 | 7 | bb = BitBucket(consumer_key, consumer_secret, 'http://localhost/', timeout=5) 8 | (result, data, error_msg) = bb.get_authorization_url() 9 | if not result: 10 | print error_msg 11 | return 12 | 13 | print 'Open the following URL: ' + data['url'] 14 | verifier = raw_input('Enter "oauth_verifier" from url: ') 15 | 16 | print 'Verifying token...' 17 | (result, data, error_msg) = bb.verify_token(data['access_token'], data['access_token_secret'], 18 | verifier) 19 | if not result: 20 | print error_msg 21 | return 22 | 23 | print 'Current user information: ' 24 | client = bb.get_authorized_client(data[0], data[1]) 25 | 26 | (result, data, error_msg) = client.get_current_user() 27 | if not result: 28 | print error_msg 29 | return 30 | 31 | print data 32 | 33 | print 'Retrieve branches and tags:' 34 | namespace = raw_input('Enter a user or team name: ') 35 | repository_name = raw_input('Enter a repository name: ') 36 | 37 | myrepo = client.for_namespace(namespace).repositories().get(repository_name) 38 | (result, data, error_msg) = myrepo.get_branches_and_tags() 39 | 40 | if not result: 41 | print error_msg 42 | return 43 | 44 | print data 45 | 46 | print 'Looking up master branch' 47 | (result, data, error_msg) = myrepo.get_branch('master') 48 | if not result: 49 | print error_msg 50 | return 51 | 52 | print data 53 | 54 | example() -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | version = "0.2" 4 | install_requires = ['requests', 'requests-oauthlib'] 5 | 6 | setup(name='py-bitbucket', 7 | version=version, 8 | description="A python client for the BitBucket API V1", 9 | long_description=open('README.md').read(), 10 | classifiers=[ 11 | "Programming Language :: Python", 12 | "Operating System :: OS Independent", 13 | "Intended Audience :: Developers" 14 | ], 15 | keywords='bitbucket api', 16 | author='Joseph Schorr', 17 | author_email='joseph.schorr@coreos.com', 18 | url='http://github.com/coreos/py-bitbucket', 19 | license=open('LICENSE').read(), 20 | packages=['bitbucket'], 21 | install_requires=install_requires, 22 | ) --------------------------------------------------------------------------------