A Python library for interacting with Polarion requirements management system. Provides utilities, core API access, extension clients, and testing helpers for SBB Polarion extensions. | Read-only mirror of https://github.com/SchweizerischeBundesbahnen/python-sbb-polarion — SBB. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-03 21:19:54 +00:00
.github ci: trust organisation-owned actions in CodeQL Actions analysis 2026-12-03 11:26:37 +01:00
python_sbb_polarion feat: support the Polarion 2612 REST API (#183) 2026-12-03 22:18:36 +01:00
tests feat: support the Polarion 2612 REST API (#183) 2026-12-03 22:18:36 +01:00
.env.example feat: migrate from Bitbucket to GitHub 2026-03-10 14:23:57 +01:00
.gitignore feat: migrate from Bitbucket to GitHub 2026-03-10 14:23:57 +01:00
.pre-commit-config.yaml chore(deps): update pre-commit hook commitizen-tools/commitizen to v4.20.1 2026-11-27 09:21:23 +00:00
.tool-versions fix: bump uv to 0.13.4 in the lock file (#150) 2026-10-21 19:38:35 +02:00
.yamlfix.toml Initial commit 2024-10-13 19:21:00 +02:00
CHANGELOG.md chore(main): release 5.2.3 (#175) 2026-12-03 14:57:22 +00:00
CLAUDE.md chore: replace mypy with ty for type checking (#152) 2026-10-22 07:01:09 +00:00
CODING_STANDARDS.md chore: replace mypy with ty for type checking (#152) 2026-10-22 07:01:09 +00:00
CONTRIBUTING.md docs: clean up outdated documentation (#25) 2026-08-19 11:27:02 +02:00
DCO feat: migrate from Bitbucket to GitHub 2026-03-10 14:23:57 +01:00
LICENSE docs: sync documentation and license from template (#95) 2026-08-19 13:41:29 +02:00
NOTICE feat: migrate from Bitbucket to GitHub 2026-03-10 14:23:57 +01:00
polarion-openapi.json feat: support the Polarion 2612 REST API (#183) 2026-12-03 22:18:36 +01:00
pyproject.toml fix(deps): update dependency ty to v0.0.115 2026-12-03 21:19:54 +00:00
README.md feat: support the Polarion 2612 REST API (#183) 2026-12-03 22:18:36 +01:00
RELEASE.md docs: clean up outdated documentation (#25) 2026-08-19 11:27:02 +02:00
renovate.json Initial commit 2024-10-13 19:21:00 +02:00
sonar-project.properties feat!: make GenericTestCase generic over the extension API type (#155) 2026-10-27 16:39:27 +01:00
tox.ini feat!: make GenericTestCase generic over the extension API type (#155) 2026-10-27 16:39:27 +01:00
uv.lock fix(deps): update dependency ty to v0.0.115 2026-12-03 21:19:54 +00:00
zizmor.yml chore: sync template — workflow permissions, claude workflow, gitleaks URL (#48) 2026-04-04 17:31:23 +02:00

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%) Lines of Code Reliability Rating Security Rating Maintainability Rating Vulnerabilities

A Python library for interacting with Polarion requirements management system. Provides utilities, core API access, extension clients, and testing helpers for SBB Polarion extensions.

Installation

The package is not published to PyPI. Each release attaches a wheel and a source distribution to its GitHub release, so install from there or directly from the repository.

# From a release asset
uv pip install https://github.com/SchweizerischeBundesbahnen/python-sbb-polarion/releases/download/v3.3.0/python_sbb_polarion-3.3.0-py3-none-any.whl

# From the repository at a tag
uv pip install "git+https://github.com/SchweizerischeBundesbahnen/python-sbb-polarion.git@v3.3.0"

# For development
git clone https://github.com/SchweizerischeBundesbahnen/python-sbb-polarion.git
cd python-sbb-polarion
uv sync --all-extras  # Install all dependencies including dev tools

Quick Start

from python_sbb_polarion.core import PolarionApiV1, ExtensionApiFactory
from python_sbb_polarion.core.base import PolarionRestApiConnection

# Create connection
connection = PolarionRestApiConnection(url="https://polarion.example.com", token="your-api-token")

# Use Polarion REST API v1 (based on Polarion 2612 OpenAPI spec)
api = PolarionApiV1(connection)
workitem = api.get_workitem("PROJECT", "ITEM-123")

# Use extension APIs via factory
pdf_api = ExtensionApiFactory.get_extension_api_by_name("pdf-exporter", connection)
result = pdf_api.convert({"projectId": "PROJECT", "documentName": "doc"})

Polarion REST API

Class Description Status
PolarionApiV1 Full Polarion REST API v1 (based on Polarion 2612) Current - use this

Current version: Polarion 2612

Removed admin-utility methods

Since Polarion 2606 the standard REST API v1 (PolarionApiV1) covers operations that the admin-utility extension client (PolarionAdminUtilityApi) used to re-implement. The extension removed those endpoints in v5.0.1, and this client removed the matching methods in 4.0.0 (deprecated since 3.0.0). Call the standard PolarionApiV1 method instead:

Removed from PolarionAdminUtilityApi Use PolarionApiV1 instead
get_project get_project
create_project create_project (standard endpoint needs an explicit location)
delete_project delete_project
create_test_run_template create_testruns (isTemplate: true)
create_collection create_collections
delete_collection delete_collection
add_to_collection create_collection_relationships (relationship documents)
create_document create_documents
create_live_report create_page
delete_live_report delete_page
get_custom_field_declarations get_global_custom_fields / get_project_custom_fields
declare_custom_field create_global_custom_fields / create_project_custom_fields
update_custom_fields_for_default_repo update_global_custom_fields
update_custom_fields_for_project update_project_custom_field
delete_custom_field_declaration no direct delete, emulate get + update of the remaining fields
set_custom_field_type update_project_custom_field / update_global_custom_fields

Admin-only methods with no standard equivalent are kept: tokens, vault records, classic wiki pages, trial-license activation, whole-document delete, default-space live reports, and XML configuration endpoints.

Documentation

  • Internal documentation: See project wiki

Project Structure

python_sbb_polarion/
├── util/           # Shared utilities (HTTP, SSH, LDAP, SQL, OAuth, mailer, etc.)
├── core/           # Core Polarion API (base classes, main API, factory)
│   └── polarion_api/       # PolarionApiV1 (current, based on Polarion 2612)
│       ├── _documents/     # Document operations
│       ├── _global/        # Global operations (users, enumerations)
│       ├── _plans/         # Plan operations
│       ├── _projects/      # Project operations
│       ├── _testruns/      # Test run operations
│       └── _workitems/     # Work item operations
├── extensions/     # Extension clients for SBB Polarion extensions
│   └── _shared_exporter/  # Shared mixins for PDF and DOCX exporters
├── linter/         # Custom code style linter (PSP001-PSP017)
├── polarion_project_manager/   # Polarion project manager
├── testing/        # Test helpers and utilities for system tests
└── types.py        # Type definitions (JsonDict, MediaType, Header, etc.)

tests/
├── unit/           # Unit tests
└── verification/   # OpenAPI verification tests

Key Modules

  • util - Reusable utilities: http, ssh, sshtunnel, ldap, sql, oauth, mailer, argparse, environment
  • core - Core API: PolarionApiV1, PolarionGenericExtensionApi, ExtensionApiFactory
  • extensions - Client interfaces for SBB Polarion extensions (pdf-exporter, docx-exporter, admin-utility, etc.)
  • linter - Custom AST-based code style linter (PSP001-PSP017)
  • testing - Test helpers: GenericTestCase, TestContainersHelper, TempProject, tear_down_all
  • testing (ui extra) - Visual regression tests of Polarion pages: PolarionUiBrowser, UiTestCase, PolarionUrls, compare_images. Install with python-sbb-polarion[ui]; Docker runs the browser
  • types - Type definitions: JsonDict, MediaType, Header, AuthScheme, file upload types

Development Commands

# Run tests
uv run tox                    # Run all tests and checks (ruff, ty, py313, py314, py315)
uv run tox -e py315           # Run unit tests only (Python 3.15)

# Linting and formatting (using Ruff)
uv run ruff check python_sbb_polarion       # Check code quality
uv run ruff format python_sbb_polarion      # Format code
uv run ruff check --fix python_sbb_polarion # Auto-fix issues

# OpenAPI verification
gh auth login                              # One-time GitHub authentication
uv run tox -e verify-openapi-mapping       # Verify extension APIs match upstream

# Build package
uv build

Code Style Linter

This library includes a custom AST-based linter that enforces code style rules beyond ruff/ty:

  • PSP001: All local variables must have type annotations
  • PSP002: api_request_* arguments must be variables (not inline dicts/f-strings)
  • PSP003: URL must be assigned to a variable before passing to API methods
  • PSP004: Query params must use params= dict, not URL concatenation
  • PSP005: Dict with type annotation must have each key-value pair on separate line
  • PSP006: Use HTTPStatus enum instead of numeric HTTP status codes
  • PSP007: Use Header enum instead of string literals for HTTP headers
  • PSP008: Use MediaType enum instead of string literals for MIME types
  • PSP009: Use AuthScheme enum instead of string literals for auth schemes
  • PSP010: Don't use quoted type annotations, use from __future__ import annotations
# CLI command (after pip install)
python-sbb-polarion-lint src/
python-sbb-polarion-lint --disable PSP001 src/
python-sbb-polarion-lint --only PSP005 src/

# Or as module
python -m python_sbb_polarion.linter src/

Programmatic usage:

from pathlib import Path
from python_sbb_polarion.linter import lint_file

violations = lint_file(Path("my_code.py"))
for v in violations:
    print(v)

Polarion Project Manager

This module provides a command-line interface for downloading, uploading, and creating Polarion project templates through PolarionProjectManager.

The CLI wraps around the core project manager class and exposes three commands:

  • download — Retrieve a project template ZIP from Polarion
  • create — Create a temporary Polarion project from a template
  • upload_template — Upload a local ZIP file as a new template
# Run as a module
python -m python_sbb_polarion.polarion_project_manager <command> [options]

Download a project template by its project ID

python -m python_sbb_polarion.polarion_project_manager download --project_id elibrary --project_group "Demo Projects" --output elibrary_st

Parameters

Parameter Default value Mandatory Description
--project_id - yes The ID of the project to download
--project_group - no The project group identifier
--output {project_id}_remote no Custom output filename without the .zip extension

Create a temporary project from a template

python -m python_sbb_polarion.polarion_project_manager create --project_id elibrary_system_test --project_name "Elibrary System Test" --template_id custom_project_template_for_st

Parameters

Parameter Default value Mandatory Description
--project_id - yes ID for the temporary project
--project_name E-Library no Display name for the temporary project
--template_id custom_project_template_for_st no Template identifier
--template_path auto-detected (first .zip in template-dir if not specified) no Path to the project template zip file

Upload a local ZIP file as a new template

python -m python_sbb_polarion.polarion_project_manager upload_template --template_id custom_project_template_for_st

Parameters

Parameter Default value Mandatory Description
--template_id custom_project_template_for_st no Template identifier
--template_path auto-detected (first .zip in template-dir if not specified) no Path to the project template zip file

Requirements

  • Python >=3.13, <3.16
  • uv package manager

License

This project is licensed under the Apache License 2.0.