This article summarizes how to invoke Altassian Of Bitbucket API And the realization of related task automation .
Updated: 2022 / 6 / 22
At present, it is feasible Bitbucket API 1’ 2
Login according to user name and password Bitbucket Server
from stashy
stash = stashy.connect()
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')
Login according to user name and password Bitbucket Server
from atlassian import Bitbucket
bitbucket = Bitbucket(
url = 'http://YourServerAddr:7990',
username = 'YourUsername',
password = 'YourPassword')
bitbucket.project.list()
bitbucket.project.list()
# {'key': ..., 'id': ..., 'name': ..., 'description': ..., 'public': ..., 'type': ..., 'links': {'self': [{'href': 'http://YourServerAdd:7990/projects/'key''}]}}
bitbucket.repo_list()
bitbucket.repo_list('YourProjectKey')
# {'slug': ..., 'id': ..., 'name': ..., 'description': ..., 'scmId': ..., 'state': ..., 'statusMessage': ..., 'forkable': ..., 'project': {'key': ..., 'id': ..., 'name': ..., 'description': ..., 'public': ..., 'type': ..., 'links': {'self': [{'href': 'http://YourServerAddr:7990/projects/YourProjectKey'}]}}, 'public': ..., 'links': {'clone': ..., [{'href': 'ssh://[email protected]: 7999/YourProjectKey/YourRepoSlug.git', 'name': 'ssh'}, {'href: 'http://YourServerAddr:7990/scm/YourProjectKey/YourReposlug.git', 'name': 'http'}], 'self': [{'href': 'http://YourServerAddr:7990/projects/YourProjectKey/repos/YourReposlug/browse'}]}
FileList = bitbucket.get_file_list(project_key = YourProjectKey, repository_slug = YourRepoSlug, sub_folder = YourFilePath, query = YourBranchName, start = FromwhereStart, limit=None)
# list(FileList) Can be listed in this Project The Repo The Branch The Subfolder Down from start All that started file name
FileCont = bitbucket.get_content_file(YourProjectKey, YourRepoSlug, YourFilePath&Name, YourBranch, markup=None)
type(FileCont)
# <class 'bytes'>
FILE = open('./FILE.csv', 'wb').write(FileCont)
with open('./File', mode='wb') as Yourfd:
bitbucket.download_repo_archive(
project_key = YourProjectKey,
repository_slug = YourRepoSlug,
dest_fd = Yourfd,
at = YourBranch,
path = YourFilePath&Name,
format = zip)
# perhaps
# fd = open('./File', mode = 'wb')
# bitbucket.download_repo_archive(
# project_key = YourProjectKey,
# repository_slug = YourRepoSlug,
# dest_fd = Yourfd,
# at = YourBranch,
# path = YourFilePath&Name,
# format = zip)
# dest_fd.close()
python api for bitbucket︎
Bitbucket API︎
stashy︎
stashy Github︎
python-bitbucket︎
atlassian-python-api︎
atlassian-python-api Github︎