- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github | ||
| python_sbb_polarion | ||
| tests | ||
| .env.example | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| .tool-versions | ||
| .yamlfix.toml | ||
| CHANGELOG.md | ||
| CLAUDE.md | ||
| CODING_STANDARDS.md | ||
| CONTRIBUTING.md | ||
| DCO | ||
| LICENSE | ||
| NOTICE | ||
| polarion-openapi.json | ||
| pyproject.toml | ||
| README.md | ||
| RELEASE.md | ||
| renovate.json | ||
| sonar-project.properties | ||
| tox.ini | ||
| uv.lock | ||
| zizmor.yml | ||
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 withpython-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
HTTPStatusenum instead of numeric HTTP status codes - PSP007: Use
Headerenum instead of string literals for HTTP headers - PSP008: Use
MediaTypeenum instead of string literals for MIME types - PSP009: Use
AuthSchemeenum 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.