# pandora-python-sdk.v2 **Repository Path**: gaozy2021/pandora-python-sdk.v2 ## Basic Information - **Project Name**: pandora-python-sdk.v2 - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: lvheyang-patch-1 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-04 - **Last Updated**: 2021-09-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python SDK for Pandora 2.0 [![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://travis-ci.com/qiniu/pandora-python-sdk.v2.svg?branch=main&status=created)](https://travis-ci.com/qiniu/pandora-python-sdk.v2) [![GitHub release](https://img.shields.io/github/v/tag/qiniu/pandora-python-sdk.v2.svg?label=release)](https://github.com/qiniu/pandora-python-sdk.v2/releases) [![Latest Stable Version](https://img.shields.io/pypi/v/pdr_python_sdk.svg)](https://pypi.python.org/pypi/pdr_python_sdk) [![Download Times](https://img.shields.io/pypi/dm/pdr_python_sdk.svg)](https://pypi.python.org/pypi/pdr_python_sdk) [![Coverage Status](https://codecov.io/gh/qiniu/pandora-python-sdk.v2/branch/main/graph/badge.svg)](https://codecov.io/gh/qiniu/pandora-python-sdk.v2) ## 安装 通过 pip 安装 ```bash $ pip install pdr_python_sdk ``` ## 运行环境 | Pandora Python SDK 版本 | Python 版本 | |:--------------------:|:---------------------------:| | 1.x | 3.8, 3.9 | ## 使用例子 ### 创建连接并上传数据 ```python from pdr_python_sdk.client import * params = { "scheme": "", "host": "localhost", "port": 80, "token": "" } conn = connect(**params) data = [ {"raw": "the raw data 1"}, {"raw": "the raw data 2"} ] conn.data_upload(data=data, repo="repo_name", sourcetype="sourcetype_name") ``` ### 使用SPL进行搜索 ```python from pdr_python_sdk.manager import * # conn 是pandora的客户端 sm = SearchManager(conn) # 搜索返回原始结构 sm.query("repo=default | stats count() by host", start=0, end=int(time.time() * 1000)) # 搜索返回pandas的dataframe结构 df = sm.query_to_pandas("repo=default | stats count() by host", start=0, end=int(time.time() * 1000)) ``` ### 自定义API ```python from pdr_python_sdk.api.on_demand_api import OnDemandApi from pdr_python_sdk.api.response import Response from pdr_python_sdk.on_demand_action import run # 自定义API返回 hello world 结果 class HelloWorldApi(OnDemandApi): def do_handle_data(self, data): if not data.contains_request(): raise Exception('api data should contain request details') request = data.request() if 'GET' != str.upper(request.method()): return Response(405, 'unsupported method [{}]'.format(str.upper(request.method()))).to_string() return Response(204, [{"hello": "world"}]).to_string() ``` ### 自定义算子 ```python from pdr_python_sdk.spl import SplStreamingBatchCommand from pdr_python_sdk.on_demand_action import run class Foobar(SplStreamingBatchCommand): def streaming_handle(self, lines): for line in lines: line['foo'] = 'bar' return lines ``` ## 更多内容 - 产品使用文档和API文档可以参考[使用文档]{https://developer.qiniu.com/express}, [API文档]{https://developer.qiniu.com/express/6468/the-preparatory-work} - 关于SDK更多的Demo,可以查看[Demo 链接]{https://github.com/qiniu/pandora-python-sdk.v2/tree/main/pdr_python_sdk/demo}。 - 如果发现了bug, 欢迎提交 [issue](https://github.com/qiniu/python-sdk/issues) - 如果有功能需求,欢迎提交 [issue](https://github.com/qiniu/python-sdk/issues) - 如果要提交代码,欢迎提交 pull request ## 代码许可 Apache-2.0 .详情见 [License文件](https://github.com/qiniu/pandora-python-sdk.v2/blob/main/LICENSE).