-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathplots.py
120 lines (85 loc) · 3.96 KB
/
plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Interface to Plotly's /v2/plots endpoints."""
from chart_studio.api.v2.utils import build_url, make_params, request
RESOURCE = "plots"
def create(body):
"""
Create a new plot.
:param (dict) body: A mapping of body param names to values.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE)
return request("post", url, json=body)
def retrieve(fid, share_key=None):
"""
Retrieve a plot from Plotly.
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:param (str) share_key: The secret key granting 'read' access if private.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid)
params = make_params(share_key=share_key)
return request("get", url, params=params)
def content(fid, share_key=None, inline_data=None, map_data=None):
"""
Retrieve the *figure* for a Plotly plot file.
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:param (str) share_key: The secret key granting 'read' access if private.
:param (bool) inline_data: If True, include the data arrays with the plot.
:param (str) map_data: Currently only accepts 'unreadable' to return a
mapping of grid-fid: grid. This is useful if you
want to maintain structure between the plot and
referenced grids when you have READ access to the
plot, but you don't have READ access to the
underlying grids.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid, route="content")
params = make_params(
share_key=share_key, inline_data=inline_data, map_data=map_data
)
return request("get", url, params=params)
def update(fid, body):
"""
Update a plot from Plotly.
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:param (dict) body: A mapping of body param names to values.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid)
return request("put", url, json=body)
def trash(fid):
"""
Soft-delete a plot from Plotly. (Can be undone with 'restore').
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid, route="trash")
return request("post", url)
def restore(fid):
"""
Restore a trashed plot from Plotly. See 'trash'.
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid, route="restore")
return request("post", url)
def permanent_delete(fid, params=None):
"""
Permanently delete a trashed plot file from Plotly. See 'trash'.
:param (str) fid: The `{username}:{idlocal}` identifier. E.g. `foo:88`.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, id=fid, route="permanent_delete")
return request("delete", url, params=params)
def lookup(path, parent=None, user=None, exists=None):
"""
Retrieve a plot file from Plotly without needing a fid.
:param (str) path: The '/'-delimited path specifying the file location.
:param (int) parent: Parent id, an integer, which the path is relative to.
:param (str) user: The username to target files for. Defaults to requestor.
:param (bool) exists: If True, don't return the full file, just a flag.
:returns: (requests.Response) Returns response directly from requests.
"""
url = build_url(RESOURCE, route="lookup")
params = make_params(path=path, parent=parent, user=user, exists=exists)
return request("get", url, params=params)