Nowadays Python is becoming very popular because it contains a wide variety of API’s that can be used to achieve any kind of functionality. On the other hand, Atlassian is becoming very popular because it is open source and very widely used.
In this article, we will discuss how two Python API's (Atlassian and keyring) can be used to create and update Confluence pages. This use case is very important when Python is used to execute test cases and in the end, it is required to publish test case results on confluence.
Atlassian API is used to update (publish) content on the confluence page and it can be downloaded from
here, whereas keyring API's come default with Python and is used to get the password of the logged-in system.
- Install Python on the system and map the pyton/pip folders to system variables.
- Clone git hub project: https://github.com/atlassian-api/atlassian-python-api
- Install Atlassian-api using following command: pip install Atlassian-python-API
- Install python keyring module using pip install keyring
- Create a keyring string using the following steps:
Under the Python file, where you want to create and update the confluence page, put the below lines of code:
- from atlassian import Confluence
- import keyring
-
- confluence = Confluence(
- url='<url of confluence page>',
- username='<username>',
- password=keyring.get_password(<keyringname>, <username))
-
-
- status = confluence.create_page(
- space='<Confluence Space (where you want to create page)>',
- title='<Page Title>',
- body='This is the body. You can use <strong>HTML tags</strong>!')
-
- print(status)
-
- status = confluence.update_page(
- parent_id=None,
- page_id=confluence.get_page_by_title(space='<Confluence Space>', title='<Page Title>')
- body='Updated Page. You can use <strong>HTML tags</strong>!')
- print(status)