Codebeamer Python API¶
This section describes the end-user facing Codebeamer API for LOBSTER.
API¶
from lobster.tools.codebeamer.codebeamer import lobster_codebeamer
lobster_codebeamer(config: Config, out_file: str)
First, prepare a configuration:
Configuration Parameters¶
Attributes accepted by AuthenticationConfig and Config when used in Python.
AuthenticationConfig¶
from lobster.tools.codebeamer.codebeamer import AuthenticationConfig
auth = AuthenticationConfig(token="<TOKEN>", root="https://codebeamer.example")
token(str | None): Bearer token for Codebeamer. Preferred over user/password.user(str | None): Username (used only iftokenis not provided).password(str | None): Password (paired withuser); may be auto-populated via~/.netrc.root(str): Base HTTPS URL of the Codebeamer instance (must start withhttps://).
Config¶
from lobster.tools.codebeamer.codebeamer import AuthenticationConfig, Config
auth = AuthenticationConfig(token="<TOKEN>", root="https://codebeamer.example")
conf = Config(
references=[],
import_tagged=None,
import_query=1234, # report ID or cbQL query string
baseline_id=None,
verify_ssl=True,
page_size=100,
schema="requirement", # or "implementation" / "activity"
timeout=30,
out=None,
num_request_retry=5,
retry_error_codes=[500, 502, 503, 504],
cb_auth_conf=auth,
item_to_text=None,
)
references(List[str]): Names of Codebeamer fields whose referenced items should be traced (converted toreqtags).import_tagged(str | None): Path to an existing LOBSTER artifact whose unresolvedreqreferences define item IDs to import.import_query(int | str | None): Report ID (int) or cbQL query string used to fetch items directly.baseline_id(int | None): Codebeamer baseline ID to query against. Only allowed whenimport_queryis a cbQL query string. Raises an error if combined withimport_taggedor a numericimport_query.verify_ssl(bool): Whether to verify TLS certificates; setTruein production for security.page_size(int): Pagination size for REST queries; a trade-off between round trips and response size (default typically 100).schema(str): Target schema type (requirement,implementation,activity) controlling class/namespace mapping.timeout(int): Per-request timeout in seconds for HTTP calls.out(str | None): Output.lobsterfilename; ifNoneyou supply one tolobster_codebeamer.num_request_retry(int): Number of retry attempts on transient failures (must be > 0).retry_error_codes(List[int]): HTTP status codes that trigger retry logic (e.g. [500, 502, 503, 504]).cb_auth_conf(AuthenticationConfig): Authentication + root endpoint.
item_to_text(Callable[[dict], str | None] | None): Optionaldelegate called once for each raw Codebeamer item. Its return value is stored in the LOBSTER
textfield for requirements and activities; returningNoneleaves the field empty. Exceptions propagate and abort thelobster_codebeamerrun. Note that this is a pure API feature and cannot be configured through YAML.
Stable API Function¶
lobster_codebeamer(config: Config, out_file: str) -> NoneLoads items (via query or tagged import) and writes them to a LOBSTER interchange file.
Example (Using the Config.item_to_text API Interface)¶
This example shows how to use the item_to_text interface to combine a
standard Codebeamer field and a custom field in the LOBSTER item’s text
property.
It assumes you have a Codebeamer instance with a custom field named
“Upstream Requirements” that contains references to other items.
The example extracts the “name” of each referenced item and appends them to the
description of the item.
from lobster.tools.codebeamer.codebeamer import AuthenticationConfig, Config, lobster_codebeamer
auth = AuthenticationConfig(
token="my_secret_token_123",
root="https://codebeamer.example.com"
)
def custom_item_to_text(item):
derived_from_field = next(
(field for field in item.get("customFields", [])
if field.get("name") == "Upstream Requirements"),
{},
)
derived_from = ", ".join(
value["name"] for value in derived_from_field.get("values", [])
)
return f"{item.get('description', '')}\nDerived from: {derived_from}"
conf = Config(
references=["Depends On", "Related To"],
import_tagged=None,
import_query=5678,
verify_ssl=True,
page_size=200,
schema="requirement",
timeout=60,
out=None,
num_request_retry=3,
retry_error_codes=[500, 502, 503, 504],
cb_auth_conf=auth,
item_to_text=custom_item_to_text,
)
lobster_codebeamer(conf, "codebeamer_items.lobster")
Core Goals¶
Fetch items using a query or report ID by setting
import_query.Fetch items referenced in an existing LOBSTER file by setting
import_tagged.Choose the item type (requirement, implementation, or activity) using
schema.Make network calls more reliable by configuring
num_request_retryandverify_ssl.Improve performance by adjusting
page_sizeandtimeout.Trace additional relationships by listing custom field names in
references.
Behavioral Notes¶
import_taggedoverridesimport_queryif both provided.schemamaps to namespace class: requirement→``req`` / implementation→``imp`` / activity→``act``.Exponential backoff is implicit (1s, 2s, 4s…) based on
num_request_retry.Missing
tokentriggers user/password or~/.netrcresolution.
Error Conditions¶
Missing/invalid
root(non-HTTPS) →KeyError.Absent both
import_query&import_tagged→KeyError.num_request_retry <= 0→ValueError.Unrecognised
schema→KeyError.baseline_idis not a positive integer →ValueError.baseline_idcombined withimport_tagged→KeyError.baseline_idcombined with numericimport_query→KeyError.