{"id":13501574,"url":"https://github.com/reportportal/client-Python","last_synced_at":"2025-03-29T09:30:52.549Z","repository":{"id":37470255,"uuid":"68000268","full_name":"reportportal/client-Python","owner":"reportportal","description":"A common client library for Python-based agents","archived":false,"fork":false,"pushed_at":"2025-03-28T14:27:23.000Z","size":1544,"stargazers_count":41,"open_issues_count":2,"forks_count":92,"subscribers_count":41,"default_branch":"develop","last_synced_at":"2025-03-28T14:37:49.958Z","etag":null,"topics":["client-python","python","reportportal","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reportportal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-12T10:41:14.000Z","updated_at":"2025-03-28T14:27:27.000Z","dependencies_parsed_at":"2023-10-11T16:14:40.989Z","dependency_job_id":"d0f8cbc9-aea5-4e73-a019-37214636dc8c","html_url":"https://github.com/reportportal/client-Python","commit_stats":{"total_commits":741,"total_committers":57,"mean_commits":13.0,"dds":0.2968960863697706,"last_synced_commit":"53dfeadefd3785782e9c1dd625cb722747d57a00"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reportportal%2Fclient-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reportportal%2Fclient-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reportportal%2Fclient-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reportportal%2Fclient-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reportportal","download_url":"https://codeload.github.com/reportportal/client-Python/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246049616,"owners_count":20715510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-python","python","reportportal","testing"],"created_at":"2024-07-31T22:01:42.066Z","updated_at":"2025-03-29T09:30:52.149Z","avatar_url":"https://github.com/reportportal.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# ReportPortal python client\n\n[![PyPI](https://img.shields.io/pypi/v/reportportal-client.svg?maxAge=259200)](https://pypi.python.org/pypi/reportportal-client)\n[![Python versions](https://img.shields.io/pypi/pyversions/reportportal-client.svg)](https://pypi.org/project/reportportal-client)\n[![Build Status](https://github.com/reportportal/client-Python/actions/workflows/tests.yml/badge.svg)](https://github.com/reportportal/client-Python/actions/workflows/tests.yml)\n[![codecov.io](https://codecov.io/gh/reportportal/client-Python/branch/develop/graph/badge.svg)](https://codecov.io/gh/reportportal/client-Python)\n[![Join Slack chat!](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://slack.epmrpp.reportportal.io/)\n[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)\n[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)\n\nLibrary used only for implementors of custom listeners for ReportPortal\n\n## Already implemented listeners:\n\n- [PyTest Framework](https://github.com/reportportal/agent-python-pytest)\n- [Robot Framework](https://github.com/reportportal/agent-Python-RobotFramework)\n- [Behave Framework](https://github.com/reportportal/agent-python-behave)\n- [Nose Framework (archived)](https://github.com/reportportal/agent-python-nosetests)\n\n## Installation\n\nThe latest stable version is available on PyPI:\n\n```\npip install reportportal-client\n```\n\n## Usage\n\nBasic usage example:\n\n```python\nimport os\nimport subprocess\nfrom mimetypes import guess_type\n\nfrom reportportal_client import RPClient\nfrom reportportal_client.helpers import timestamp\n\nendpoint = \"http://docker.local:8080\"\nproject = \"default\"\n# You can get UUID from user profile page in the ReportPortal.\napi_key = \"1adf271d-505f-44a8-ad71-0afbdf8c83bd\"\nlaunch_name = \"Test launch\"\nlaunch_doc = \"Testing logging with attachment.\"\n\n\nclient = RPClient(endpoint=endpoint, project=project,\n                  api_key=api_key)\n\n# Start log upload thread\nclient.start()\n\n# Start launch.\nlaunch = client.start_launch(name=launch_name,\n                             start_time=timestamp(),\n                             description=launch_doc)\n\nitem_id = client.start_test_item(name=\"Test Case\",\n                                 description=\"First Test Case\",\n                                 start_time=timestamp(),\n                                 attributes=[{\"key\": \"key\", \"value\": \"value\"},\n                                             {\"value\", \"tag\"}],\n                                 item_type=\"STEP\",\n                                 parameters={\"key1\": \"val1\",\n                                             \"key2\": \"val2\"})\n\n# Create text log message with INFO level.\nclient.log(time=timestamp(),\n           message=\"Hello World!\",\n           level=\"INFO\")\n\n# Create log message with attached text output and WARN level.\nclient.log(time=timestamp(),\n           message=\"Too high memory usage!\",\n           level=\"WARN\",\n           attachment={\n               \"name\": \"free_memory.txt\",\n               \"data\": subprocess.check_output(\"free -h\".split()),\n               \"mime\": \"text/plain\"\n           })\n\n# Create log message with binary file, INFO level and custom mimetype.\nimage = \"/tmp/image.png\"\nwith open(image, \"rb\") as fh:\n    attachment = {\n        \"name\": os.path.basename(image),\n        \"data\": fh.read(),\n        \"mime\": guess_type(image)[0] or \"application/octet-stream\"\n    }\n    client.log(timestamp(), \"Screen shot of issue.\", \"INFO\", attachment)\n\nclient.finish_test_item(item_id=item_id, end_time=timestamp(), status=\"PASSED\")\n\n# Finish launch.\nclient.finish_launch(end_time=timestamp())\n\n# Due to async nature of the service we need to call terminate() method which\n# ensures all pending requests to server are processed.\n# Failure to call terminate() may result in lost data.\nclient.terminate()\n```\n\n# Send attachment (screenshots)\n\nThe client uses `requests` library for working with RP and the same semantics\nto work with attachments (data).\n\nTo log an attachment you need to pass file content and metadata to ``\n\n```python\nimport logging\n\nfrom reportportal_client import RPLogger, RPLogHandler\n\nlogging.setLoggerClass(RPLogger)\nrp_logger = logging.getLogger(__name__)\nrp_logger.setLevel(logging.DEBUG)\nrp_logger.addHandler(RPLogHandler())\n\nscreenshot_file_path = 'path/to/file.png'\n\nwith open(screenshot_file_path, \"rb\") as image_file:\n    file_data = image_file.read()\n\n    # noinspection PyArgumentList\n    rp_logger.info(\n        \"Some Text Here\",\n        attachment={\"name\": \"test_name_screenshot.png\",\n                    \"data\": file_data,\n                    \"mime\": \"image/png\"}\n    )\n```\n\n# Copyright Notice\n\nLicensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)\nlicense (see the LICENSE.txt file).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freportportal%2Fclient-Python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freportportal%2Fclient-Python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freportportal%2Fclient-Python/lists"}