Bitbucket API
Asked by Kyaw:

Dear All,

I am exploring BitBucket Module of Python API with below URL.

<https://atlassian-python-api.readthedocs.io/bitbucket.html>

However, I am still can't find the right python packages to use "bitbucket"

```
# Project listbitbucket.project_list()
```

I am keen to work for the following methods

Manage projects {#toc-hId--1183469851}
--------------------------------------

Manage repositories {#toc-hId-1304042982}
-----------------------------------------

Manage Code Insights {#toc-hId--503411481}
------------------------------------------

Groups and admins {#toc-hId-1984101352}
---------------------------------------

Manage code {#toc-hId-176646889}
--------------------------------

Branch permissions {#toc-hId--1630807574}
-----------------------------------------

Pull Request management {#toc-hId-856705259}
--------------------------------------------

Conditions-Reviewers management {#toc-hId--950749204}
-----------------------------------------------------

Pipelines management {#toc-hId-1536763629}
------------------------------------------

Manage issues {#toc-hId--270690834}
-----------------------------------

Since I am rushing for my experiment and I hope someone will advise me to move forward quickly.

Best regards


Answers:
author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540) Welcome to Atlassian Community

do this install from pip

**pip install atlassian-python-api**

and in code use this

```
from atlassian import Bitbucket
```

Link for same here <https://atlassian-python-api.readthedocs.io/index.html>

comments: author: Kyaw
body: Hi Vishwas,

Thanks for your prompt reply and I used it below  
from atlassian import Jira  
from atlassian import Confluence  
from atlassian import Bitbucket  
from atlassian import ServiceDesk  
from atlassian import Xray  

bitbucket = Bitbucket(  
url='<http://localhost:9090>',  
username='admin',  
password='admin')  
However, I am not able to call these APIs.  
I hope you will advise me since I am new for the Atlassian APIs.  

```
# Project listbitbucket.project_list()
```

```
# Get single repositorybitbucket.get_repo(project_key, repository_slug)
```

```
 
```

```
# Get repositories list from projectbitbucket.repo_list(project_key, limit=25)
```

```
# Decline pull requestbitbucket.decline_pull_request(project_key, repository, pr_id, pr_version)
```

```
?
```

```
# Object oriented:    # Get the repository first    r = cloud.workspaces.get(workspace).repositories.get(repository)
```


author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

Check this link here <https://github.com/atlassian-api/atlassian-python-api/blob/master/examples/bitbucket/bitbucket_cloud_oo.py>

A sample example is mentioned there.

Let me know in case of any questions.


author: Kyaw
body: Hi Vishwas,

Thanks for your help and pls advise me where can I have this URL <https://api.bitbucket.org>.

Since I have only this <https://bitbucket.org/mrkyawkyawoo/>

Also could it be possible to experiment locally first like below  
bitbucket = Bitbucket(  
url='<http://localhost:9090>',  
username='admin',  
password='admin')  
Best regards


author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

You are in bitbucket cloud.

so the api url to be used is [https://api.bitbucket.org](https://api.bitbucket.org/)

This part is authentication for server which doesn't work in your case

bitbucket = Bitbucket(  
url='[http://localhost:9090](http://localhost:9090/)',  
username='admin',  
password='admin')  
Check this part in the doc :  

```
# Log-in with E-Mail / Username and regular password# or with Username and App password.# Get App password from https://bitbucket.org/account/settings/app-passwords/.# Log-in with E-Mail and App password not possible.# Username can be found here: https://bitbucket.org/account/settings/from atlassian.bitbucket import Cloudbitbucket = Cloud(    username=bitbucket_email,    password=bitbucket_password,    cloud=True)bitbucket_app_pw = Cloud(    username=bitbucket_username,    password=bitbucket_app_password,    cloud=True)
```


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381)

That mean I need to open and use developer account instead of local server.

If the developer account, then how should I do or is it free or payable service?

Is there any way to use local server's experiment first before Cloud for the above assessment(<https://atlassian-python-api.readthedocs.io/bitbucket.html#>) ?

Best regards


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

This URL <https://pypi.org/project/bitbucket-python/> is working with

bitbucket_email = " "  
bitbucket_password = " "

client = Client(bitbucket_email, bitbucket_password)

However, it is not enough for my use case since I would like to do like this URL <https://atlassian-python-api.readthedocs.io/bitbucket.html#>

But, I didn't have the proper Python package to install and set the Configuration yet.

Really appreciate your kind help soon.

Best regards


author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

Firstly i would like to understand the hosting you are on, without that i can't suggest.

But in generic let me answer the queries you have.

*That mean I need to open and use developer account instead of local server. --\>* there is no need to open developer account for this. If you are on bitbucket cloud <https://bitbucket.org/> you can generate an app password and use it in the API query.

But I understand that you are in <https://bitbucket.org/> this only as mentioned above <https://bitbucket.org/mrkyawkyawoo/>. So navigate here and create app password <https://bitbucket.org/account/settings/app-passwords/>

*If the developer account, then how should I do or is it free or payable service? --\>*Bitbucket free plan is there, so no need to pay anything for developer account

*Is there any way to use local server's experiment first before Cloud for the above assessment(<https://atlassian-python-api.readthedocs.io/bitbucket.html#>) ? -\>*

Yes, you may have to install a local server of bitbucket datacentre variant to try them out <https://www.atlassian.com/software/bitbucket/download/data-center>

KB on how to install <https://confluence.atlassian.com/bitbucketserver/install-bitbucket-data-center-872139817.html>

Lastly

*But, I didn't have the proper Python package to install and set the Configuration yet. -\>* what type of package are you expecting ?

This pip library **pip install atlassian-python-api** should be enough for you to use the API mentioned here <https://atlassian-python-api.readthedocs.io/bitbucket.html#>


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) .

Thanks for prompt and detailed info.

I will try again first these <https://atlassian-python-api.readthedocs.io/bitbucket.html#>

However, I am still not getting to use the object instance of **bitbucket(initial configuration)** as below

from atlassian import Jira  
from atlassian import Confluence  
from atlassian import Bitbucket  
from atlassian import ServiceDesk  
from atlassian import Xray  
from XXXXX import XXXXX -\> **Import package name ?**

<br />

**bitbucket** = XXXX(bitbucket_email, bitbucket_password)

```
bitbucket.project_list()
```

```
bitbucket.get_repo(project_key, repository_slug)
```

```
# Delete an existing Code Insights reportbitbucket.delete_code_insights_report(project_key, repository_slug, commit_hash, report_key)

```

```
# Decline pull requestbitbucket.decline_pull_request(project_key, repository, pr_id, pr_version
```

```
# Object oriented:    # Get the repository first    r = cloud.workspaces.get(workspace).repositories.get(repository)
```

Really appreciate your kind and prompt response.

Best regards


author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

I get it now

Its this line for bitbucket cloud

```
from atlassian.bitbucket import Cloud
```

and this in case of server/dc

```
from atlassian import Bitbucket
```


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381)

Here is

```
from atlassian import Bitbucket
```

**Bitbucket** -\> **bitbucket =\> how can I get this pls ?**  
How to instantiate like this ?  
bitbucket = Bitbucket(  
url='<http://localhost:7990>',  
username=user_name,  
password=pass_word)

```
bitbucket.project_list()
```


author: Vishwas
body: I don't understand sir :( Really confused here. Are you on server or cloud ?

the part is bitbucket server
> bitbucket = Bitbucket(  
> url='[http://localhost:7990](http://localhost:7990/)',  
> username=user_name,  
password=pass_word)  
to do this do we have bitbucket hosted on Virtual Machine ? To test like above we need a on-premise bitbucket application without that we can't.


author: Kyaw
body: Good day [@Vishwas](/t5/user/viewprofilepage/user-id/1231381)

Sorry for my confused questions and I am using currently

<https://bitbucket.org/mrkyawkyawoo/>  
bitbucket_email = ""  
bitbucket_password = ""  
from bitbucket.client import Client  
client = Client(bitbucket_email, bitbucket_password)  
# Get user information  
response = client.get_user()  
# print(response)  
Above these are working well.  
**I am not sure how to configure using the package below to call**  
**from atlassian import Bitbucket**  

```
bitbucket.project_list()
```

```
bitbucket.get_repo(project_key, repository_slug)
```

```
# Delete an existing Code Insights reportbitbucket.delete_code_insights_report(project_key, repository_slug, commit_hash, report_key)

```

```
# Decline pull requestbitbucket.decline_pull_request(project_key, repository, pr_id, pr_version
```

```
# Object oriented:    # Get the repository first    r = cloud.workspaces.get(workspace).repositories.get(repository)
```


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

Is it possible to have a short discussion of my use case via any communication channel like zoom, hangout, skype and so on pls ?

If it so how about today or tomorrow to expedite the process pls?

Best regards


author: Vishwas
body: Hey [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

Not a problem, we at community are here to suggest and guide on best possible way.

When using cloud API there is no need to use this package

**from atlassian import Bitbucket**

I have also not much expertise on this but can guide you on the basic to get you going.

You can send a Zoom or hangout invite.


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

Thanks for your lots of advice and before sending the zoom pls let me know your time zone with your available time pls.


author: Vishwas
body: [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

I'm at IST time zone. That is +05:30 GMT. You can send me invite around 1:00 PM IST. Is that okay for you. I'm not sure which time zone you are in it could be late for you.

Or else you can send the invite in late evenings here.


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

How about 8 PM of IST time today pls ?

If fine then pls your email to send the zoom invitation link.


author: Vishwas
body: yes


author: Kyaw
body: [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

just sent and see you today 8 PM(IST) with your acknowledgement email pls.


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381)

Are you there pls ?


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381) ,

Most of the read API may work Python Programmatically but will try to write something onwards.

Thanks for last late evening catch up and see you today again as usual time if you were fine.


author: Vishwas
body: Hi [@Kyaw](/t5/user/viewprofilepage/user-id/4766540)

Sure i would like to join and learn.


author: Kyaw
body: Hi [@Vishwas](/t5/user/viewprofilepage/user-id/1231381)

I am zoom and are you busy ?


Tags: bitbucket-cloud

cloud