Skip to main content

An API Client for the Polarion REST API

Project description

polarion-rest-api-client

image image

A client library for accessing Polarion REST API. This project consists of multiple layers. There is a high level, still incomplete version of the client and a feature complete low level API client, which was generated using an OpenAPI generator. Therefore the OpenAPI Specification of Polarion was used.

Usage of the High Level Client

The high level client is an abstraction of the fine-grained, auto-generated client. It is non project specific, however, for most operations, you need to create a project specific one from the generic one. All created created project clients share the client session of the generic client. To get started, create a client and check, if the project exists. In the end, to get all Work Items of a project with an empty query, you can simply run the following code and our client will automatically take care of the paging:

import polarion_rest_api_client as polarion_api

client = polarion_api.PolarionClient(
   polarion_api_endpoint="http://127.0.0.1/api",
   polarion_access_token="PAT123",
)
project_client = client.generate_project_client("PROJ")
project_exists = project_client.exists() # Should be True
work_items = project_client.work_items.get_all()

During the initialization of the client you can define additional settings like the page size when getting items or the maximum content size when bulk creating new items. In addition, you can define your own Work Item class with custom fields, which become available as attributes on object level instead of being part of the additional_attributes dictionary only. To use this feature, inherit from our Work Item class and pass your extended class when requesting Work Items:

import polarion_rest_api_client as polarion_api
import dataclasses

@dataclasses.dataclass
class CustomWorkItem(polarion_api.WorkItem):
   capella_uuid: str | None = None

client = polarion_api.PolarionClient(
   polarion_api_endpoint="http://127.0.0.1/api",
   polarion_access_token="PAT123",
)
project_client = client.generate_project_client("PROJ")
work_items = project_client.work_items.get_all(work_item_cls=CustomWorkItem)
uuid = work_items[0].capella_uuid # the value of the custom field capella_uuid can be accessed this way

Usage of the autogenerated OpenAPI Client

First, create a client:

from polarion_rest_api_client.open_api_client import Client

client = Client(base_url="https://api.example.com")

If the endpoints you're going to hit require authentication, use AuthenticatedClient instead:

from polarion_rest_api_client.open_api_client import AuthenticatedClient

client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")

Now call your endpoint and use your models:

from polarion_rest_api_client.open_api_client.models import MyDataModel
from polarion_rest_api_client.open_api_client.api.my_tag import get_my_data_model
from polarion_rest_api_client.open_api_client.types import Response

my_data: MyDataModel = get_my_data_model.sync(client=client)
# or if you need more info (e.g. status_code)
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)

Or do the same thing with an async version:

from polarion_rest_api_client.open_api_client.models import MyDataModel
from polarion_rest_api_client.open_api_client.api.my_tag import get_my_data_model
from polarion_rest_api_client.open_api_client.types import Response

my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)

By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.

client = AuthenticatedClient(
    base_url="https://internal_api.example.com",
    token="SuperSecretToken",
    verify_ssl="/path/to/certificate_bundle.pem",
)

You can also disable certificate validation altogether, but beware that this is a security risk.

client = AuthenticatedClient(
    base_url="https://internal_api.example.com",
    token="SuperSecretToken",
    verify_ssl=False
)

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info.

Things to know:

  1. Every path/method combo becomes a Python module with four functions:

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. All path/query params, and bodies become method arguments.

  3. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)

  4. Any endpoint which did not have a tag will be in polarion_rest_api_client.open_api_client.api.default

Documentation

Read the full documentation on Github pages.

Installation

You can install the latest released version directly from PyPI.

pip install polarion-rest-api-client

To set up a development environment, clone the project and install it into a virtual environment.

git clone https://github.com/DSD-DBS/polarion-rest-api-client
cd polarion-rest-api-client
python -m venv .venv

source .venv/bin/activate.sh  # for Linux / Mac
.venv\Scripts\activate  # for Windows

pip install -U pip pre-commit
pip install -e '.[docs,test]'
pre-commit install

Updating the auto generated part

To update the auto generated part of the code, execute the open_api_client_build/build_client.py script with path or url as first arg and the path to the OpenAPI-Specification as second arg from the project root directory. The publicly available specification from the Polarion developer Portal was used.

Please note that as of Polarion 24.10 there is a mistake in the specification. In the relationships of a work items the type of approvals has to be "workrecords" according to the specification, but in fact it is "workitem_approvals". For that reason we added a fixed version of the specification to this repository and the issue will be reported to SIEMENS.

Contributing

We'd love to see your bug reports and improvement suggestions! Please take a look at our guidelines for contributors for details.

Licenses

This project is compliant with the REUSE Specification Version 3.0.

Copyright DB InfraGO AG, licensed under Apache 2.0 (see full text in LICENSES/Apache-2.0.txt)

Dot-files are licensed under CC0-1.0 (see full text in LICENSES/CC0-1.0.txt)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polarion_rest_api_client-1.4.3.tar.gz (656.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polarion_rest_api_client-1.4.3-py3-none-any.whl (2.8 MB view details)

Uploaded Python 3

File details

Details for the file polarion_rest_api_client-1.4.3.tar.gz.

File metadata

  • Download URL: polarion_rest_api_client-1.4.3.tar.gz
  • Upload date:
  • Size: 656.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for polarion_rest_api_client-1.4.3.tar.gz
Algorithm Hash digest
SHA256 5a6727d3bddc4f94cbe1a0ab8041fcfcda432b3d1704c1ee3ddae7e1419c1460
MD5 ae6ef4a2622b5d37b8b56a848f82e113
BLAKE2b-256 a813c6cdd872af00d2fc69c35a3116c14e46fd398322e2b41b71c02b36dec4de

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarion_rest_api_client-1.4.3.tar.gz:

Publisher: build-test-publish.yml on DSD-DBS/polarion-rest-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polarion_rest_api_client-1.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for polarion_rest_api_client-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d90266905acd561438440b7c5d5148bc0a1e1d5f7ee0557c69ef7f2292f6078
MD5 cf4a69a528a86216f8d7166dcd07d561
BLAKE2b-256 2773f90be0160d263bf1cf6d38df0bd0467b056497dd84a99fe03346a8d0a811

See more details on using hashes here.

Provenance

The following attestation bundles were made for polarion_rest_api_client-1.4.3-py3-none-any.whl:

Publisher: build-test-publish.yml on DSD-DBS/polarion-rest-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page