| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,3 +7,7 @@ | |||
| 7 | 7 | Untitled0.ipynb | |
| 8 | 8 | ||
| 9 | 9 | *.ipynb | |
| 10 | + | ||
| 11 | + build | ||
| 12 | + | ||
| 13 | + dist | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,4 +2,5 @@ | |||
| 2 | 2 | from .plotly import signup | |
| 3 | 3 | from .plotly import display | |
| 4 | 4 | from .plotly import embed | |
| 5 | - from .plotly import plotly | ||
| 5 | + from .plotly import plotly | ||
| 6 | + from .plotly import stream | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | import requests | |
| 2 | 2 | import json | |
| 3 | 3 | import warnings | |
| 4 | + import httplib | ||
| 4 | 5 | ||
| 5 | 6 | from .version import __version__ | |
| 6 | 7 | ||
@@ -250,5 +251,53 @@ def __makecall(self, args, un, key, origin, kwargs): | |||
| 250 | 251 | ||
| 251 | 252 | return r | |
| 252 | 253 | ||
| 254 | + class stream: | ||
| 255 | + def __init__(self, token): | ||
| 256 | + ''' plotly stream constructor | ||
| 257 | + token found at https://plot.ly/settings | ||
| 258 | + ''' | ||
| 259 | + self.token = token | ||
| 260 | + self.connected = False | ||
| 261 | + | ||
| 262 | + def init(self): | ||
| 263 | + ''' Initialize a streaming connection to plotly | ||
| 264 | + ''' | ||
| 265 | + self.conn = httplib.HTTPConnection('stream.plot.ly', 80) | ||
| 266 | + self.conn.putrequest('POST', '/') | ||
| 267 | + self.conn.putheader('Host', 'stream.plot.ly') | ||
| 268 | + self.conn.putheader('User-Agent', 'Python-Plotly') | ||
| 269 | + self.conn.putheader('Transfer-Encoding', 'chunked') | ||
| 270 | + self.conn.putheader('Connection', 'close') | ||
| 271 | + self.conn.putheader('plotly-streamtoken', self.token) | ||
| 272 | + self.conn.endheaders() | ||
| 273 | + self.connected=True | ||
| 274 | + | ||
| 275 | + def write(self, data): | ||
| 276 | + ''' Write data to plotly's streaming servers | ||
| 253 | 277 | ||
| 278 | + data is a plotly formatted data dict | ||
| 279 | + with data keys 'x', 'y', 'text', 'z', 'marker', 'line' | ||
| 280 | + 'x', 'y', 'text', and 'z' can have values of strings, numbers, or lists | ||
| 281 | + 'marker', and 'line' have dicts as values with keys 'size', 'color', 'symbol' | ||
| 254 | 282 | ||
| 283 | + Examples: | ||
| 284 | + {'x': 1, 'y': 2} | ||
| 285 | + {'x': [1, 2, 3], 'y': [10, 20, 30]} | ||
| 286 | + {'x': 1, 'y': 3, 'text': 'hover text'} | ||
| 287 | + {'x': 1, 'y': 3, 'marker': {'color': 'blue'}} | ||
| 288 | + {'z': [[1,2,3], [4,5,6]]} | ||
| 289 | + ''' | ||
| 290 | + if not self.connected: | ||
| 291 | + self.init() | ||
| 292 | + # plotly's streaming API takes new-line separated json objects | ||
| 293 | + msg = json.dumps(data)+'\n' | ||
| 294 | + msglen = format(len(msg), 'x') | ||
| 295 | + # chunked encoding requests contain the messege length in hex, \r\n, and then the message | ||
| 296 | + self.conn.send('{msglen}\r\n{msg}\r\n'.format(msglen=msglen, msg=msg)) | ||
| 297 | + | ||
| 298 | + def close(self): | ||
| 299 | + ''' Close connection to plotly's streaming servers | ||
| 300 | + ''' | ||
| 301 | + self.conn.send('0\r\n\r\n') | ||
| 302 | + self.conn.close() | ||
| 303 | + self.connected=False | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1 +1 @@ | |||
| 1 | - __version__ = '0.5.10' | ||
| 1 | + __version__ = '0.5.11' | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,26 @@ | |||
| 1 | 1 | from setuptools import setup | |
| 2 | 2 | exec(open('plotly/version.py').read()) | |
| 3 | + | ||
| 3 | 4 | def readme(): | |
| 4 | 5 | with open('README.txt') as f: | |
| 5 | 6 | return f.read() | |
| 6 | 7 | ||
| 7 | 8 | setup(name='plotly', | |
| 8 | 9 | version=__version__, | |
| 10 | + use_2to3=True, | ||
| 9 | 11 | author='Chris P', | |
| 10 | 12 | author_email='chris@plot.ly', | |
| 11 | 13 | maintainer='Chris P', | |
| 12 | 14 | maintainer_email='chris@plot.ly', | |
| 13 | 15 | url='https://plot.ly/api/python', | |
| 14 | 16 | description='Python plotting library for collaborative, interactive, web-based, publication-quality graphs.', | |
| 15 | 17 | long_description=readme(), | |
| 16 | - classifiers=['Development Status :: 4 - Beta', | ||
| 17 | - 'Programming Language :: Python :: 2.7', | ||
| 18 | - 'Programming Language :: Python :: 3.3', | ||
| 19 | - 'Topic :: Scientific/Engineering :: Visualization', | ||
| 20 | - ], | ||
| 18 | + classifiers=[ | ||
| 19 | + 'Development Status :: 4 - Beta', | ||
| 20 | + 'Programming Language :: Python :: 2.7', | ||
| 21 | + 'Programming Language :: Python :: 3.3', | ||
| 22 | + 'Topic :: Scientific/Engineering :: Visualization', | ||
| 23 | + ], | ||
| 21 | 24 | license='MIT', | |
| 22 | 25 | packages=['plotly'], | |
| 23 | 26 | install_requires=[ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments