# ReportPortal python client
[![PyPI](https://img.shields.io/pypi/v/reportportal-client.svg?maxAge=259200)](https://pypi.python.org/pypi/reportportal-client)
[![Python versions](https://img.shields.io/pypi/pyversions/reportportal-client.svg)](https://pypi.org/project/reportportal-client)
[![Build Status](https://github.com/reportportal/client-Python/actions/workflows/tests.yml/badge.svg)](https://github.com/reportportal/client-Python/actions/workflows/tests.yml)
[![codecov.io](https://codecov.io/gh/reportportal/client-Python/branch/develop/graph/badge.svg)](https://codecov.io/gh/reportportal/client-Python)
[![Join Slack chat!](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)
Library used only for implementors of custom listeners for ReportPortal
## Already implemented listeners:
- [PyTest Framework](https://github.com/reportportal/agent-python-pytest)
- [Robot Framework](https://github.com/reportportal/agent-Python-RobotFramework)
- [Behave Framework](https://github.com/reportportal/agent-python-behave)
- [Nose Framework (archived)](https://github.com/reportportal/agent-python-nosetests)
## Installation
The latest stable version is available on PyPI:
```
pip install reportportal-client
```
## Usage
Basic usage example:
```python
import os
import subprocess
from mimetypes import guess_type
from reportportal_client import RPClient
from reportportal_client.helpers import timestamp
endpoint = "http://docker.local:8080"
project = "default"
# You can get UUID from user profile page in the ReportPortal.
api_key = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
launch_name = "Test launch"
launch_doc = "Testing logging with attachment."
client = RPClient(endpoint=endpoint, project=project,
api_key=api_key)
# Start log upload thread
client.start()
# Start launch.
launch = client.start_launch(name=launch_name,
start_time=timestamp(),
description=launch_doc)
item_id = client.start_test_item(name="Test Case",
description="First Test Case",
start_time=timestamp(),
attributes=[{"key": "key", "value": "value"},
{"value", "tag"}],
item_type="STEP",
parameters={"key1": "val1",
"key2": "val2"})
# Create text log message with INFO level.
client.log(time=timestamp(),
message="Hello World!",
level="INFO")
# Create log message with attached text output and WARN level.
client.log(time=timestamp(),
message="Too high memory usage!",
level="WARN",
attachment={
"name": "free_memory.txt",
"data": subprocess.check_output("free -h".split()),
"mime": "text/plain"
})
# Create log message with binary file, INFO level and custom mimetype.
image = "/tmp/image.png"
with open(image, "rb") as fh:
attachment = {
"name": os.path.basename(image),
"data": fh.read(),
"mime": guess_type(image)[0] or "application/octet-stream"
}
client.log(timestamp(), "Screen shot of issue.", "INFO", attachment)
client.finish_test_item(item_id=item_id, end_time=timestamp(), status="PASSED")
# Finish launch.
client.finish_launch(end_time=timestamp())
# Due to async nature of the service we need to call terminate() method which
# ensures all pending requests to server are processed.
# Failure to call terminate() may result in lost data.
client.terminate()
```
# Send attachment (screenshots)
The client uses `requests` library for working with RP and the same semantics
to work with attachments (data).
To log an attachment you need to pass file content and metadata to ``
```python
import logging
from reportportal_client import RPLogger, RPLogHandler
logging.setLoggerClass(RPLogger)
rp_logger = logging.getLogger(__name__)
rp_logger.setLevel(logging.DEBUG)
rp_logger.addHandler(RPLogHandler())
screenshot_file_path = 'path/to/file.png'
with open(screenshot_file_path, "rb") as image_file:
file_data = image_file.read()
# noinspection PyArgumentList
rp_logger.info(
"Some Text Here",
attachment={"name": "test_name_screenshot.png",
"data": file_data,
"mime": "image/png"}
)
```
# Copyright Notice
Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
license (see the LICENSE.txt file).
Raw data
{
"_id": null,
"home_page": "https://github.com/reportportal/client-Python",
"name": "reportportal-client",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "testing, reporting, reportportal, client",
"author": "ReportPortal Team",
"author_email": "support@reportportal.io",
"download_url": "https://files.pythonhosted.org/packages/74/77/e09f9ae05a9a57cbcfec70435dfabfdbe1d85c302e11a7973fc5c63cd263/reportportal_client-5.6.0.tar.gz",
"platform": null,
"description": "# 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-\u2764%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",
"bugtrack_url": null,
"license": "Apache 2.0.",
"summary": "Python client for ReportPortal v5.",
"version": "5.6.0",
"project_urls": {
"Download": "https://github.com/reportportal/client-Python/tarball/5.6.0",
"Homepage": "https://github.com/reportportal/client-Python"
},
"split_keywords": [
"testing",
" reporting",
" reportportal",
" client"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5a48d12658bcd3bcc2b07fa84618cfc1096cbb0bbe45614616e0ae922d7aabc2",
"md5": "5db6496154772563e421d342467d6c32",
"sha256": "8e9b18542a392b0ac011adec31cc6c002c690980d21125b3acdec18b0ac3e488"
},
"downloads": -1,
"filename": "reportportal_client-5.6.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "5db6496154772563e421d342467d6c32",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 77486,
"upload_time": "2024-12-19T15:51:37",
"upload_time_iso_8601": "2024-12-19T15:51:37.356182Z",
"url": "https://files.pythonhosted.org/packages/5a/48/d12658bcd3bcc2b07fa84618cfc1096cbb0bbe45614616e0ae922d7aabc2/reportportal_client-5.6.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7477e09f9ae05a9a57cbcfec70435dfabfdbe1d85c302e11a7973fc5c63cd263",
"md5": "1fe913be68f5c3c41d1981e52971ce8d",
"sha256": "438ecfd4771863c108285b7bc030ed5d480e1696147533f3991c55d65d6cfad4"
},
"downloads": -1,
"filename": "reportportal_client-5.6.0.tar.gz",
"has_sig": false,
"md5_digest": "1fe913be68f5c3c41d1981e52971ce8d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 59940,
"upload_time": "2024-12-19T15:51:40",
"upload_time_iso_8601": "2024-12-19T15:51:40.576843Z",
"url": "https://files.pythonhosted.org/packages/74/77/e09f9ae05a9a57cbcfec70435dfabfdbe1d85c302e11a7973fc5c63cd263/reportportal_client-5.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-19 15:51:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "reportportal",
"github_project": "client-Python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "aenum",
"specs": []
},
{
"name": "requests",
"specs": [
[
">=",
"2.32.3"
]
]
},
{
"name": "aiohttp",
"specs": [
[
">=",
"3.10.11"
]
]
},
{
"name": "certifi",
"specs": [
[
">=",
"2024.8.30"
]
]
}
],
"tox": true,
"lcname": "reportportal-client"
}