pushdata.io的python客户端库

pushdata-io的Python项目详细描述


pushdata python客户端库

此库允许您使用联机服务pushdata.io轻松存储和检索时间序列数据。

安装

pip install pushdata-io

开始

您可以立即开始在pushdata.io上存储数据,甚至不必在那里注册帐户。只需安装此软件包并编写三行代码,如下所示:

importpushdatapd=pushdata.Client(email="youremail@yourdomain.com",tsname="MyTimeseries")pd.send(12345)# Stores the data point 12345, timestamped with the current date and time

运行代码并存储至少一个数据点后,转到https://pushdata.io/youremail@yourdomain.com可以在其中查看时间序列。

用法

importpushdata# 1. Initialize with no authentication# Initialize with our account email and time series name we want to usepd=pushdata.Client(email="myemail@example.com",tsname="mytimeseries")# 2. ...or initialize with authentication (for account with security=on)pd=pushdata.Client(apikey="thd8JT73LsB8jah0F4d9",tsname="mytimeseries")# Send a data point to the time seriespd.send(4711)# Send to another time series by overriding tsnamepd.send(4711,tsname="myothertimeseries")# Retrieve all data from the time seriesresponse=pd.recv()# Or from another time seriesresponse=pd.recv(tsname="anothertimeseries")# Retrieve data timestamped during the last weekimportdatetimeone_week_ago=datetime.datetime.now()-datetime.timedelta(days=7)response=pd.recv(fromtime=one_week_ago)# Retrieve data for one 24-hour period, one week agoimportdatetimeone_week_ago=datetime.datetime.now()-datetime.timedelta(days=7)one_week_ago_plus_24h=one_week_ago+datetime.timedelta(days=1)response=pd.recv(fromtime=one_week_ago,totime=one_week_ago_plus_24h)## Print time series data## We get a Python Requests response object from recv(), which # includes response code, raw HTTP response body, and more.# We use the .json() method to parse the body text as JSON# and get a dictionary:tsdata=response.json()## And then we print stuff:print("Timeseries name: "+tsdata["name"])print("First point recorded at   : "+tsdata["first"])# timestamp of first point in time seriesprint("Last point recorded at    : "+tsdata["last"])# timestamp of last point in time seriesprint("Total number of points    : "+tsdata["total"])# total number of points in timeseriesprint("Number of points returned : "+tsdata["returned"])# number of points returned in this callprint("---- Points ----")forpointintsdata["points"]:print("Time=%s value=%f"%(point["time"],point["value"]))## tsdata (the decoded JSON response from pushdata.io) is # a dictionary that looks like this:#  {#     "name": "mytimeseries",#     "first": "2019-02-15T07:43:31.546805Z",#     "last": "2019-03-05T11:21:06.20951Z",#     "total": 482,#     "returned: 482,#     "offset": 0,#     "limit": 10000,#     "points": [#        {#           "time": "2019-02-15T07:43:31.546805Z",#           "value": 4711.0#        },#        ...#     ]#  }## See https://speca.io/ragnarlonn/pushdata-io#TimeSeriesData#

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
由于外键约束,java数据库插入失败   java在对失败的测试用例截图时出错,并且它没有附加到扩展报告中   java FragmentPagerAdapter总是从第一页开始   java内存泄漏,当我将数据从一个树存储库复制到另一个ext js 4.1时   java确保带有特定注释的字段是“私有的”   Java如何将UTC毫秒转换为UTC日期   开源Java:Solaris上的AWT   java为什么BufferedReader只读取第一行?   执行数据库查询时,java JTable不会刷新   java 7中的下划线和二进制文字。!!!??   java使用STaX将xml转换为另一个xml需要很多时间   hadoop如何使用JavaAPI从hbase中的表中选择特定列   使用JLabel的java拖放   用于“绘制”pdf文件的pdf生成Java库   java getResourceAsStream返回null?   java在目标帧中打开窗口   滚动对象时,java鼠标光标不会改变   java有人能解释二进制搜索树中的递归delete()并帮我转换它吗