{"id":4741,"library":"reportportal-client","title":"ReportPortal Python Client","description":"The reportportal-client is a Python client library for integrating test automation results with ReportPortal v5. It provides functionalities to manage launches, test items, and logs, including attachments. The current version is 5.7.4, and the library generally sees frequent minor updates, often several per month.","status":"active","version":"5.7.4","language":"en","source_language":"en","source_url":"https://github.com/reportportal/client-Python","tags":["testing","reporting","automation","client","logs"],"install":[{"cmd":"pip install reportportal-client","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for asynchronous HTTP requests to the ReportPortal API. Its version was updated in 5.7.2.","package":"aiohttp","optional":false}],"imports":[{"note":"RPClient is the main entry point for interacting with the ReportPortal API.","wrong":"import RPClient","symbol":"RPClient","correct":"from reportportal_client import RPClient"},{"note":"RPLogHandler is used for integrating with Python's standard logging module. Its path moved to the top-level package.","wrong":"from reportportal_client.logs import RPLogHandler","symbol":"RPLogHandler","correct":"from reportportal_client import RPLogHandler"},{"note":"RPLogger is a custom logging class extending Python's Logger, often used in conjunction with RPLogHandler. Its path moved to the top-level package.","wrong":"from reportportal_client.logs import RPLogger","symbol":"RPLogger","correct":"from reportportal_client import RPLogger"},{"note":"A helper function to generate timestamps in the format expected by ReportPortal.","symbol":"timestamp","correct":"from reportportal_client.helpers import timestamp"}],"quickstart":{"code":"import os\nimport subprocess\nfrom mimetypes import guess_type\nimport logging\n\nfrom reportportal_client import RPClient, RPLogger, RPLogHandler\nfrom reportportal_client.helpers import timestamp\n\n# Configure logging for the client itself (optional, but good practice)\nlogging.basicConfig(level=logging.DEBUG)\n\n# ReportPortal configuration from environment variables\nendpoint = os.environ.get('RP_ENDPOINT', 'http://localhost:8080/api/v1')\nproject = os.environ.get('RP_PROJECT', 'default_personal')\napi_key = os.environ.get('RP_API_KEY', 'YOUR_API_KEY') # Get from your ReportPortal User Profile\nlaunch_name = 'Example Launch'\nlaunch_doc = 'Basic example of using reportportal-client.'\n\n# Set up ReportPortal logger\nlogging.setLoggerClass(RPLogger)\nrp_logger = logging.getLogger(__name__)\nrp_logger.setLevel(logging.INFO)\nrp_logger.addHandler(RPLogHandler(endpoint=endpoint, project=project, api_key=api_key, launch_uuid=None))\n\ntry:\n    # Initialize RPClient\n    client = RPClient(endpoint=endpoint, project=project, api_key=api_key)\n    # Start log upload thread (for async mode)\n    client.start()\n\n    # Start a new launch\n    launch = client.start_launch(\n        name=launch_name,\n        start_time=timestamp(),\n        description=launch_doc,\n        attributes=[{'key': 'client', 'value': 'python'}, {'value', 'example'}]\n    )\n    launch_uuid = launch.uuid\n    rp_logger.info(f'Launch started with UUID: {launch_uuid}')\n\n    # Start a test item (e.g., a test case or suite)\n    test_item = client.start_test_item(\n        name='Test Case 1',\n        description='First Test Case',\n        start_time=timestamp(),\n        attributes=[{'key': 'suite', 'value': 'smoke'}],\n        item_type='STEP',\n        launch_uuid=launch_uuid\n    )\n    test_item_uuid = test_item.uuid\n    rp_logger.info(f'Test Item started with UUID: {test_item_uuid}')\n\n    # Log messages\n    client.log(time=timestamp(), message='Hello from ReportPortal Client!', level='INFO', launch_uuid=launch_uuid, item_uuid=test_item_uuid)\n    rp_logger.warning('This is a warning log using the standard Python logger.', attachment={\n        'name': 'warning.txt',\n        'data': b'This is an attached text file content.',\n        'mime': 'text/plain'\n    })\n\n    # Simulate a subprocess call and attach output\n    try:\n        output = subprocess.check_output(['ls', '-l'], stderr=subprocess.STDOUT)\n        client.log(time=timestamp(), message='ls -l output', level='DEBUG', launch_uuid=launch_uuid, item_uuid=test_item_uuid, attachment={\n            'name': 'ls_output.txt',\n            'data': output,\n            'mime': 'text/plain'\n        })\n    except subprocess.CalledProcessError as e:\n        client.log(time=timestamp(), message=f'Command failed: {e.output.decode()}', level='ERROR', launch_uuid=launch_uuid, item_uuid=test_item_uuid)\n\n    # Finish the test item\n    client.finish_test_item(item_uuid=test_item_uuid, end_time=timestamp(), status='PASSED', launch_uuid=launch_uuid)\n    rp_logger.info(f'Test Item {test_item_uuid} finished.')\n\n    # Finish the launch\n    client.finish_launch(launch_uuid=launch_uuid, end_time=timestamp(), status='PASSED')\n    rp_logger.info(f'Launch {launch_uuid} finished.')\n\nexcept Exception as e:\n    rp_logger.error(f'An error occurred: {e}')\nfinally:\n    # It's crucial to call terminate() to ensure all pending requests are sent to ReportPortal\n    client.terminate()\n    rp_logger.info('Client terminated, all pending logs sent.')","lang":"python","description":"This quickstart demonstrates the basic usage of the ReportPortal Python client, including starting and finishing a launch, creating test items (steps), logging messages, and attaching files. It also shows how to integrate the client with Python's standard logging module using `RPLogger` and `RPLogHandler`. Environment variables are used for ReportPortal configuration (RP_ENDPOINT, RP_PROJECT, RP_API_KEY) for secure execution. The `client.terminate()` call in the finally block is essential for asynchronous operations."},"warnings":[{"fix":"Upgrade Python to version 3.9 or newer.","message":"Python 3.8 support was officially removed in version 5.7.0. Projects using Python 3.8 or older will need to upgrade their Python version to use recent client versions.","severity":"breaking","affected_versions":">=5.7.0"},{"fix":"Update import statements from `from reportportal_client.log_manager import ...` to `from reportportal_client import ...`.","message":"The `log_manager.py` module, which included classes like `RPLogger` and `RPLogHandler`, was removed in version 5.7.0. These classes are now directly available under the top-level `reportportal_client` package.","severity":"breaking","affected_versions":">=5.7.0"},{"fix":"Update your ReportPortal configuration (e.g., `pytest.ini`, environment variables) to use `log_batch_payload_limit` instead of `log_batch_payload_size` for controlling the maximum payload size of asynchronous log requests.","message":"The configuration parameter `log_batch_payload_size` was renamed to `log_batch_payload_limit` in version 5.6.7. If you use a custom configuration file or environment variables with the old name, it will no longer be recognized.","severity":"gotcha","affected_versions":">=5.6.7"},{"fix":"Review your code for any usage of `NOT_FOUND` constant and remove or replace it with appropriate error handling or status checks.","message":"The `NOT_FOUND` constant was removed in version 5.6.3 as it caused infinite issues according to release notes.","severity":"breaking","affected_versions":">=5.6.3"},{"fix":"Always ensure `client.terminate()` is called in a `finally` block or at the end of your test execution logic.","message":"When using the client in asynchronous mode (which is default for `RPClient`), it is crucial to call `client.terminate()` after all test operations are complete. Failing to do so may result in unsent logs or test items, as pending requests may not be flushed to the ReportPortal server.","severity":"gotcha","affected_versions":"All versions with async client"},{"fix":"Provide either the `api_key` or a complete set of OAuth 2.0 parameters (`rp_oauth_uri`, `rp_oauth_username`, `rp_oauth_password`, `rp_oauth_client_id`). Avoid providing both if you intend to use API Key authentication.","message":"ReportPortal supports both API Key and OAuth 2.0 Password Grant authentication. If both API key and OAuth parameters are provided, OAuth 2.0 authentication will take precedence. Ensure your configuration correctly specifies the desired authentication method.","severity":"gotcha","affected_versions":"All 5.x versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}