8000 Update to_plotly_json docstring, and add new to_json_string helper method by itsluketwist · Pull Request #4301 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

Update to_plotly_json docstring, and add new to_json_string helper method #4301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 22, 2023
Prev Previous commit
Next Next commit
Use faster plotly.io serialization.
  • Loading branch information
itsluketwist committed Aug 18, 2023
commit 7ef805c87df8a6f3889f97396933730aa46b772b
27 changes: 25 additions & 2 deletions packages/python/plotly/plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5609,15 +5609,38 @@ def to_plotly_json(self):
"""
return deepcopy(self._props if self._props is not None else {})

def to_json(self):
def to_json(self, *args, **kwargs):
"""
Convert to a JSON string representation.

Parameters
----------
validate: bool (default True)
True if the figure should be validated before being converted to
JSON, False otherwise.

pretty: bool (default False)
True if JSON representation should be pretty-printed, False if
representation should be as compact as possible.

remove_uids: bool (default True)
True if trace UIDs should be omitted from the JSON representation

engine: str (default None)
The JSON encoding engine to use. One of:
- "json" for an encoder based on the built-in Python json module
- "orjson" for a fast encoder the requires the orjson package
If not specified, the default encoder is set to the current value of
plotly.io.json.config.default_encoder.

Returns
-------
str
Representation of figure as a JSON string
"""
return json.dumps(self.to_plotly_json(), cls=PlotlyJSONEncoder)
import plotly.io as pio

return pio.to_json(self, *args, **kwargs)

@staticmethod
def _vals_equal(v1, v2):
Expand Down
0