Library Internals
module: .metaclasses
The .metaclasses
module contains - as one might
expect - metaclasses that are used to ensure a consistent interface
throughout the Highcharts for Python library.
class: HighchartsMeta
- class HighchartsMeta(**kwargs)[source]
Metaclass that is used to define the standard interface exposed for serializable objects.
Class Inheritance
- classmethod _copy_dict_key(key, original, other, overwrite=True, **kwargs)[source]
Copies the value of
key
fromoriginal
toother
.
- abstract classmethod _get_kwargs_from_dict(as_dict)[source]
Convenience method which returns the keyword arguments used to initialize the class from a Highcharts Javascript-compatible
dict
object.
- _process_required_modules(scripts=None, include_extension=False) List[str] [source]
Return the list of URLs from which the Highcharts JavaScript modules needed to render the chart can be retrieved.
- abstract _to_untrimmed_dict(in_cls=None) dict [source]
Generate the first-level of the
dict
representation of the object.Note
This method does not traverse the object structure to convert the object into a full
dict
representation - it merely goes “part” of the way there to replace the Highcharts for Python keys with their correpsond Highcharts JS keys.- Return type:
- _untrimmed_mro_ancestors(in_cls=None) dict [source]
Walk through the parent classes and consolidate the results of their
_to_untrimmed_dict()
methods into a singledict
.- Return type:
- classmethod _validate_js_literal(as_str, range=True, _break_loop_on_failure=False)[source]
Parse
as_str
as a valid JavaScript literal object.- Parameters:
- Returns:
The parsed AST representation of
as_str
and the updated string.- Return type:
- copy(other=None, overwrite=True, **kwargs)[source]
Copy the configuration settings from this instance to the
other
instance.- Parameters:
other (
HighchartsMeta
) – The target instance to which the properties of this instance should be copied. IfNone
, will create a new instance and populate it with properties copied fromself
. Defaults toNone
.overwrite (
bool
) – ifTrue
, properties inother
that are already set will be overwritten by their counterparts inself
. Defaults toTrue
.kwargs – Additional keyword arguments. Some special descendents of
HighchartsMeta
may have special implementations of this method which rely on additional keyword arguments.
- Returns:
A mutated version of
other
with new property values
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)[source]
Construct an instance of the class from a
dict
object.- Parameters:
- Returns:
A Python object representation of
as_dict
.- Return type:
- classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)[source]
Return a Python object representation of a Highcharts JavaScript object literal.
- Parameters:
as_str_or_file (
str
) – The JavaScript object literal, represented either as astr
or as a filename which contains the JS object literal.allow_snake_case (
bool
) – IfTrue
, interpretssnake_case
keys as equivalent tocamelCase
keys. Defaults toTrue
._break_loop_on_failure (
bool
) – IfTrue
, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults toFalse
.
- Returns:
A Python object representation of the Highcharts JavaScript object literal.
- Return type:
- classmethod from_json(as_json_or_file, allow_snake_case: bool = True)[source]
Construct an instance of the class from a JSON string.
- Parameters:
as_json_or_file – The JSON string for the object or the filename of a file that contains the JSON string.
allow_snake_case (
bool
) – IfTrue
, interpretssnake_case
keys as equivalent tocamelCase
keys. Defaults toTrue
.
- Returns:
A Python objcet representation of
as_json
.- Return type:
- get_required_modules(include_extension=False) List[str] [source]
Return the list of URLs from which the Highcharts JavaScript modules needed to render the chart can be retrieved.
- to_dict() dict [source]
Generate a
dict
representation of the object compatible with the Highcharts JavaScript library.Note
The
dict
representation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.
- to_js_literal(filename=None, encoding='utf-8', careful_validation=False) str | None [source]
Return the object represented as a
str
containing the JavaScript object literal.- Parameters:
along the way using the esprima-python library. Defaults to
False
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- to_json(filename=None, encoding='utf-8', for_export: bool = False)[source]
Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.
Note
This method will either return a standard
str
or abytes
object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytes
representation of the string.- Parameters:
filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to
None
encoding (
str
) – The character encoding to apply to the resulting object. Defaults to'utf-8'
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
A JSON representation of the object compatible with the Highcharts library.
- Return type:
- static trim_dict(untrimmed: dict, to_json: bool = False, context: str = None, for_export: bool = False) dict [source]
Remove keys from
untrimmed
whose values areNone
and convert values that have.to_dict()
methods.- Parameters:
untrimmed (
dict
) – Thedict
whose values may still beNone
or Python objects.to_json (
bool
) – IfTrue
, will remove all keys fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
Trimmed
dict
- Return type:
- static trim_iterable(untrimmed, to_json=False, context: str = None, for_export: bool = False)[source]
Convert any
EnforcedNullType
values inuntrimmed
to'null'
.- Parameters:
untrimmed (iterable) – The iterable whose members may still be
None
or Python objects.to_json (
bool
) – IfTrue
, will remove all members fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Return type:
iterable
class: JavaScriptDict
- class JavaScriptDict(dict=None, /, **kwargs)[source]
Special
dict
class which constructs a JavaScript object that can be represented as a string.Keys are validated to be valid variable names, while values are validated to be strings.
When serialized to
str
, keys are not wrapped in double quotes (as they would be in JSON) to ensure that the resulting string can be evaluated as JavaScript code.Class Inheritance
- classmethod _validate_js_literal(as_str, range=True, _break_loop_on_failure=False)[source]
Parse
as_str
as a valid JavaScript literal object.- Parameters:
- Returns:
The parsed AST representation of
as_str
and the updated string.- Return type:
- clear() None. Remove all items from D.
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)[source]
Construct an instance of the class from a
dict
object.- Parameters:
- Returns:
A Python object representation of
as_dict
.- Return type:
- classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)[source]
Return a Python object representation of a Highcharts JavaScript object literal.
- Parameters:
as_str_or_file (
str
) – The JavaScript object literal, represented either as astr
or as a filename which contains the JS object literal.allow_snake_case (
bool
) – IfTrue
, interpretssnake_case
keys as equivalent tocamelCase
keys. Defaults toTrue
._break_loop_on_failure (
bool
) – IfTrue
, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults toFalse
.
- Returns:
A Python object representation of the Highcharts JavaScript object literal.
- Return type:
- classmethod from_json(as_json)[source]
Construct an instance of the class from a JSON string.
- Parameters:
- Returns:
A Python objcet representation of
as_json
.- Return type:
- get(k[, d]) D[k] if k in D, else d. d defaults to None.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
- to_dict()[source]
Generate a
dict
representation of the object compatible with the Highcharts JavaScript library.Note
The
dict
representation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.
- to_js_literal(filename=None, encoding='utf-8', careful_validation=False) str | None [source]
Return the object represented as a
str
containing the JavaScript object literal.- Parameters:
along the way using the esprima-python library. Defaults to
False
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- to_json(filename=None, encoding='utf-8', for_export: bool = False)[source]
Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.
Note
This method will either return a standard
str
or abytes
object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytes
representation of the string.- Parameters:
filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to
None
encoding (
str
) – The character encoding to apply to the resulting object. Defaults to'utf8'
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
A JSON representation of the object compatible with the Highcharts library.
- Return type:
- static trim_dict(untrimmed: dict, to_json: bool = False, context: str = None, for_export: bool = False) dict [source]
Remove keys from
untrimmed
whose values areNone
and convert values that have.to_dict()
methods.- Parameters:
untrimmed (
dict
) – Thedict
whose values may still beNone
or Python objects.to_json (
bool
) – IfTrue
, will remove all keys fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Returns:
Trimmed
dict
- Return type:
- static trim_iterable(untrimmed, to_json=False, context: str = None, for_export: bool = False)[source]
Convert any
EnforcedNullType
values inuntrimmed
to'null'
.- Parameters:
untrimmed (iterable) – The iterable whose members may still be
None
or Python objects.to_json (
bool
) – IfTrue
, will remove all members fromuntrimmed
that are not serializable to JSON. Defaults toFalse
.context (
str
orNone
) – If provided, will inform the method of the context in which it is being run which may inform special handling cases (e.g. where empty strings may be important / allowable). Defaults toNone
.for_export (
bool
) – IfTrue
, indicates that the method is being run to produce a JSON for consumption by the export server. Defaults toFalse
.
- Return type:
iterable
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values
module: .decorators
The .decorators
module contains decorators and
decorator-assisting functions used throughout the Highcharts for Python library.
decorator: @class_sensitive
- @class_sensitive(types=None, allow_dict=True, allow_json=True, allow_none=True, allow_js_literal=True, force_iterable=False)[source]
Validates that the values passed to a decorated function or method are de-serialized to the appropriate type.
- Parameters:
types –
type
object or iterable oftype
objects used to indicate which types are allowed. The first (or only) item intypes
will indicate the primary type thatvalue
will be returned as.allow_dict (
bool
) – IfTrue
, will accept adict
object asvalue
. Defaults toTrue
.allow_json (
bool
) – IfTrue
, will accept astr
object asvalue
, under the assumption that is is deserializable as JSON. Defaults toTrue
.allow_none (
bool
) – IfTrue
, will accept an empty orNone
object asvalue
. Defaults toTrue
.allow_js_literal (
bool
) – IfTrue
, will accept astr
object asvalue
, under the assumption that it is deserializable as a JavaScript object literal. Defaults toTrue
.force_iterable (
bool
) – IfTrue
, will accept an iterable object asvalue
. Defaults toFalse
(because most attributes are just singletons).
- Types:
Note
To apply the decorator to a property setter method (the most-common use case), place it after the
@<property name>.setter
decorator and directly above the function name like so:@some_property.setter @class_sensitive(...) def some_property(self, value): ...
- Returns:
The result of the decorated function or method having validated the class typing.
- Raises:
HighchartsImplementationError – if
types
is emptyHighchartsValueError – if
types
does not contain atype
or iterable oftype
objectsHighchartsValueError – if the primary type does not conform to the
HighchartsMeta
interface definition
function: validate_types()
- validate_types(value, types=None, allow_dict=True, allow_json=True, allow_none=True, allow_js_literal=True, force_iterable=False, function_name=None)[source]
Validates that
value
is one or more of the allowed types, where the first type passed intypes
is the primary type that it will be returned as.- Parameters:
value (Any) – The value to be validated.
types –
type
object or iterable oftype
objects used to indicate which types are allowed. The first (or only) item intypes
will indicate the primary type thatvalue
will be returned as.allow_dict (
bool
) – IfTrue
, will accept adict
object asvalue
. Defaults toTrue
.allow_json (
bool
) – IfTrue
, will accept astr
object asvalue
, under the assumption that is is deserializable as JSON. Defaults toTrue
.allow_none (
bool
) – IfTrue
, will accept an empty orNone
object asvalue
. Defaults toTrue
.allow_js_literal (
bool
) – IfTrue
, will accept astr
object asvalue
, under the assumption that it is deserializable as a JavaScript object literal. Defaults toTrue
.force_iterable (
bool
) – IfTrue
, will accept an iterable object asvalue
. Defaults toFalse
(because most attributes are just singletons).function_name (
str
) – The optional name of the function that was originally called.
- Types:
- Returns:
value
de-serialized to the primary type (firsttype
intypes
)- Return type:
first
type
intypes
- Raises:
HighchartsImplementationError – if
types
is emptyHighchartsValueError – if
types
does not contain atype
or iterable oftype
objectsHighchartsValueError – if the primary type does not conform to the
HighchartsMeta
interface definition
module:: .js_literal_functions
The .js_literal_functions
module contains
functions that are used to parse, process, de-serialize, and serialize JavaScript literal
notation.
function: serialize_to_js_literal()
- serialize_to_js_literal(item, encoding='utf-8', ignore_to_array=False, careful_validation=False) str | None [source]
Convert
item
to the contents of a JavaScript object literal code snippet.- Parameters:
item – A value that is to be converted into a JS object literal notation value.
encoding (
str
) – The character encoding to apply to the resulting object. Defaults to'utf-8'
.ignore_to_array (
bool
) – IfTrue
, will ignore handling of the.to_array()
method to break recursion. Defaults toFalse
.careful_validation (
bool
) –if
True
, will carefully validate JavaScript values along the way using the esprima-python library. Defaults toFalse
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- Returns:
A JavaScript object literal code snippet, expressed as a string. Or
None
ifitem
is not serializable.- Return type:
function: attempt_variable_declaration()
function: is_js_function_or_class()
- is_js_function_or_class(as_str, careful_validation=False) bool [source]
Determine whether
as_str
is a JavaScript function or not.- Parameters:
as_str (
str
) – The string to evaluate.careful_validation (
bool
) –if
True
, will carefully validate JavaScript values along the way using the esprima-python library. Defaults toFalse
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- Returns:
True
ifas_str
is a JavaScript function.False
if not.- Return type:
function: get_js_literal()
- get_js_literal(item, careful_validation=False) str [source]
Convert the value of
item
into a JavaScript literal string.- Parameters:
careful_validation (
bool
) –if
True
, will carefully validate JavaScript values along the way using the esprima-python library. Defaults toFalse
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.- Returns:
The JavaScript literal string.
- Return type:
function: assemble_js_literal()
- assemble_js_literal(as_dict, keys_as_strings=False, careful_validation=False) str | None [source]
Convert
as_dict
into a JavaScript object literal string.- Parameters:
as_dict (
dict
) – Adict
representation of the JavaScript object.keys_as_strings (
bool
) – ifTrue
, will return the keys as string values (wrapped in quotation marks). IfFalse
, will return the keys as object literals. Defaults toFalse
.careful_validation (
bool
) –if
True
, will carefully validate JavaScript values along the way using the esprima-python library. Defaults toFalse
.Warning
Setting this value to
True
will significantly degrade serialization performance, though it may prove useful for debugging purposes.
- Returns:
The JavaScript object literal representation of
as_dict
.- Return type:
function: convert_js_literal_to_python()
function: convert_js_property_to_python()
function: convert_js_to_python()
function: get_key_value_pairs()
- get_key_value_pairs(properties, original_str)[source]
Return the key and value pairs for properties defined in
properties
.
.utility_functions
The .utility_functions
module contains a
small number of functions which serve as utilities across the Highcharts for Python
library. Think of it as a function “catch all” module.
function:: mro_to_dict()
function:: get_remaining_mro()
function:: mro__to_untrimmed_dict()
- mro__to_untrimmed_dict(obj, in_cls=None)[source]
Traverse the ancestor classes of
obj
and execute their_to_untrimmed_dict()
methods.- Parameters:
obj (
HighchartsMeta
) – The object to be traversed.in_cls (
type
orNone
) – The class from whichmro__to_untrimmed_dict()
was called.
- Returns:
Collection of untrimmed
dict
representations in the same order as the MRO.- Return type:
for each class in the MRO, execute _to_untrimmed_dict() do not repeat for each class
function:: validate_color()
function:: to_camelCase()
function:: to_snake_case()
function:: parse_csv()
- parse_csv(csv_data, has_header_row=True, delimiter=',', null_text='None', wrapper_character="'", wrap_all_strings=False, double_wrapper_character_when_nested=False, escape_character='\\', line_terminator='\r\n')[source]
Parse
csv_data
to return a list ofdict
objects, one for each record.- Parameters:
- Returns:
Collection of column names (or numerical keys) and CSV records as
dict
values- Return type:
module: .ai
The .ai
module contains - as one might
expect - functions that enable Highcharts for Python to communicate with
supported generative AI platforms. These functions are used to convert
Python callables to their JavaScript equivalents in the
CallbackFunction.from_python()
method.
function:: convert_to_js()
- convert_to_js(callable, model='gpt-3.5-turbo', api_key=None, openai_api_type=None, openai_api_base=None, openai_api_version=None, openai_deployment_id=None, **kwargs)[source]
Converts
source
into a JavaScript function.- Parameters:
callable (callable) – The Python callable to convert.
model (
str
) –The generative AI model to use. Defaults to
'gpt-3.5-turbo'
. Accepts:'gpt-3.5-turbo'
(default)'gpt-3.5-turbo-16k'
'gpt-4'
'gpt-4-32k'
'gpt-4-1106-preview'
'gpt-4-vision-preview'
'claude-instant-1'
'claude-2'
The API key used to authenticate against the generative AI provider. Defaults to
None
, which then tries to find the API key in the appropriate environment variable:openai_api_type (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to'azure'
. Defaults toNone
.openai_api_base (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your base API endpoint. Defaults toNone
.openai_api_version (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your API version. Defaults toNone
.openai_deployment_id (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your deployment ID. Defaults toNone
.**kwargs –
Additional keyword arguments which are passed to the underlying model API. Useful for advanced configuration of the model’s behavior.
- Returns:
The JavaScript source code produced by the model.
Warning
Generating the JavaScript source code is not deterministic. That means that it may not be correct, and we STRONGLY recommend reviewing it before using it in a production application.
Every single generative AI is known to have issues - whether “hallucinations”, biases, or incoherence. We cannot stress enough:
DO NOT RELY ON AI-GENERATED CODE IN PRODUCTION WITHOUT HUMAN REVIEW.
That being said, for “quick and dirty” EDA, fast prototyping, etc. the functionality may be “good enough”.
- Return type:
- Raises:
HighchartsValueError – if
callable
is not a Python callableHighchartsValueError – if no
api_key
is availableHighchartsDependencyError – if a required dependency is not available in the runtime environment
HighchartsModerationError – if using an OpenAI model, and OpenAI detects that the supplied input violates their usage policies
HighchartsPythonConversionError – if the model was unable to convert
callable
into JavaScript source code
function:: openai_moderate()
- openai_moderate(prompt, api_key=None, api_type=None, api_base=None, api_version=None, deployment_id=None)[source]
Evaluates
prompt
against OpenAI’s content moderation policies to determine if it violates their usage policies.This function calls OpenAI’s moderation API to evaluate whether
prompt
violates their content moderation policies.- Parameters:
prompt (
str
) – The prompt to evaluate.api_key (
str
orNone
) – The API key used to authenticate with OpenAI. Defaults toNone
, which then tries to find the API key in theOPENAI_API_KEY
.api_type (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to'azure'
. Defaults toNone
.api_base (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your base API endpoint. Defaults toNone
.api_version (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your API version. Defaults toNone
.deployment_id (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your deployment ID. Defaults toNone
.
- Returns:
A
tuple
containing two members:- Return type:
- Raises:
HighchartsDependencyError – if openai is not installed/available in the runtime environment
HighchartsValueError – if no
api_key
is available
function:: openai_conversion()
- openai_conversion(prompt, model='gpt-3.5-turbo', api_key=None, api_type=None, api_base=None, api_version=None, deployment_id=None, **kwargs)[source]
Submits
prompt
to the OpenAI API for conversion into JavaScript source code.- Parameters:
prompt (
list
ofdict
) – The prompt to evaluate, using the Chat Completions form with a few-shot strategy.model (
str
) –The generative AI model to use. Defaults to
'gpt-3.5-turbo'
. Accepts:'gpt-3.5-turbo'
(default)'gpt-3.5-turbo-16k'
'gpt-4'
'gpt-4-32k'
api_key (
str
orNone
) – The API key used to authenticate against OpenAI. Defaults toNone
, which then tries to find theOPENAI_API_KEY
environment variable.api_type (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to'azure'
. Defaults toNone
.api_base (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your base API endpoint. Defaults toNone
.api_version (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your API version. Defaults toNone
.deployment_id (
str
orNone
) – If using OpenAI and Azure endpoints, this value should be set to your deployment ID. Defaults toNone
.**kwargs –
Additional keyword arguments which are passed to the underlying model API. Useful for advanced configuration of the model’s behavior.
- Returns:
The JavaScript source code produced by the model.
Warning
Generating the JavaScript source code is not deterministic. That means that it may not be correct, and we STRONGLY recommend reviewing it before using it in a production application.
Every single generative AI is known to have issues - whether “hallucinations”, biases, or incoherence. We cannot stress enough:
DO NOT RELY ON AI-GENERATED CODE IN PRODUCTION WITHOUT HUMAN REVIEW.
That being said, for “quick and dirty” EDA, fast prototyping, etc. the functionality may be “good enough”.
- Return type:
- Raises:
HighchartsValueError – if no
api_key
is availableHighchartsDependencyError – if a required dependency is not available in the runtime environment
function:: anthropic_conversion()
- anthropic_conversion(prompt, model='gpt-3.5-turbo', api_key=None, **kwargs)[source]
Submits
prompt
to the Anthropic API for conversion into JavaScript source code.- Parameters:
prompt (
str
) – The prompt to evaluate.model (
str
) –The generative AI model to use. Defaults to
'claude-instant-1'
. Accepts:'claude-instant-1'
'claude-2'
api_key (
str
orNone
) – The API key used to authenticate against OpenAI. Defaults toNone
, which then tries to find theANTHROPIC_API_KEY
environment variable.**kwargs –
Additional keyword arguments which are passed to the underlying model API. Useful for advanced configuration of the model’s behavior.
- Returns:
The JavaScript source code produced by the model.
Warning
Generating the JavaScript source code is not deterministic. That means that it may not be correct, and we STRONGLY recommend reviewing it before using it in a production application.
Every single generative AI is known to have issues - whether “hallucinations”, biases, or incoherence. We cannot stress enough:
DO NOT RELY ON AI-GENERATED CODE IN PRODUCTION WITHOUT HUMAN REVIEW.
That being said, for “quick and dirty” EDA, fast prototyping, etc. the functionality may be “good enough”.
- Return type:
- Raises:
HighchartsValueError – if no
api_key
is availableHighchartsDependencyError – if a required dependency is not available in the runtime environment
function:: get_source()
- get_source(callable)[source]
Retrieve the source of
callable
.- Parameters:
callable (callable) – The Python callable object (function or method).
- Returns:
The source code of
callable
.- Return type:
- Raises:
HighchartsValueError – if
callable
is not a Python callableHighchartsDependencyError – if dill is not installed