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 - keyfrom- originalto- other.
 - 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 - dictobject.
 - abstract _to_untrimmed_dict(in_cls=None) dict[source]
- Generate the first-level of the - dictrepresentation of the object.- Note - This method does not traverse the object structure to convert the object into a full - dictrepresentation - 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 single- dict.- Return type:
 
 - classmethod _validate_js_literal(as_str, range=True, _break_loop_on_failure=False)[source]
- Parse - as_stras a valid JavaScript literal object.- Parameters:
- Returns:
- The parsed AST representation of - as_strand the updated string.
- Return type:
 
 - copy(other=None, overwrite=True, **kwargs)[source]
- Copy the configuration settings from this instance to the - otherinstance.- Parameters:
- other ( - HighchartsMeta) – The target instance to which the properties of this instance should be copied. If- None, will create a new instance and populate it with properties copied from- self. Defaults to- None.
- overwrite ( - bool) – if- True, properties in- otherthat are already set will be overwritten by their counterparts in- self. Defaults to- True.
- kwargs – Additional keyword arguments. Some special descendents of - HighchartsMetamay have special implementations of this method which rely on additional keyword arguments.
 
- Returns:
- A mutated version of - otherwith new property values
 
 - classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)[source]
- Construct an instance of the class from a - dictobject.- 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 a- stror as a filename which contains the JS object literal.
- allow_snake_case ( - bool) – If- True, interprets- snake_casekeys as equivalent to- camelCasekeys. Defaults to- True.
- _break_loop_on_failure ( - bool) – If- True, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults to- False.
 
- 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) – If- True, interprets- snake_casekeys as equivalent to- camelCasekeys. Defaults to- True.
 
- Returns:
- A Python objcet representation of - as_json.
- Return type:
 
 - to_dict() dict[source]
- Generate a - dictrepresentation of the object compatible with the Highcharts JavaScript library.- Note - The - dictrepresentation 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') str | None[source]
- Return the object represented as a - strcontaining the JavaScript object literal.
 - to_json(filename=None, encoding='utf-8')[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 - stror a- bytesobject depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a- bytesrepresentation of the string.- Parameters:
- Returns:
- A JSON representation of the object compatible with the Highcharts library. 
- Return type:
 
 - static trim_dict(untrimmed: dict, to_json: bool = False) dict[source]
- Remove keys from - untrimmedwhose values are- Noneand convert values that have- .to_dict()methods.
 
class: JavaScriptDict
- class JavaScriptDict(dict=None, /, **kwargs)[source]
- Special - dictclass 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_stras a valid JavaScript literal object.- Parameters:
- Returns:
- The parsed AST representation of - as_strand the updated string.
- Return type:
 
 - clear() None. Remove all items from D.
 - classmethod from_dict(as_dict)[source]
- Construct an instance of the class from a - dictobject.- Parameters:
- Returns:
- A Python object representation of - as_dict.
- 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 - dictrepresentation of the object compatible with the Highcharts JavaScript library.- Note - The - dictrepresentation 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') str | None[source]
- Return the object represented as a - strcontaining the JavaScript object literal.
 - to_json(filename=None, encoding='utf-8')[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 - stror a- bytesobject depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a- bytesrepresentation of the string.- Parameters:
- Returns:
- A JSON representation of the object compatible with the Highcharts library. 
- Return type:
 
 - 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 – - typeobject or iterable of- typeobjects used to indicate which types are allowed. The first (or only) item in- typeswill indicate the primary type that- valuewill be returned as.
- allow_dict ( - bool) – If- True, will accept a- dictobject as- value. Defaults to- True.
- allow_json ( - bool) – If- True, will accept a- strobject as- value, under the assumption that is is deserializable as JSON. Defaults to- True.
- allow_none ( - bool) – If- True, will accept an empty or- Noneobject as- value. Defaults to- True.
- allow_js_literal ( - bool) – If- True, will accept a- strobject as- value, under the assumption that it is deserializable as a JavaScript object literal. Defaults to- True.
- force_iterable ( - bool) – If- True, will accept an iterable object as- value. Defaults to- False(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>.setterdecorator 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 - typesis empty
- HighchartsValueError – if - typesdoes not contain a- typeor iterable of- typeobjects
- HighchartsValueError – if the primary type does not conform to the - HighchartsMetainterface 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 - valueis one or more of the allowed types, where the first type passed in- typesis the primary type that it will be returned as.- Parameters:
- value (Any) – The value to be validated. 
- types – - typeobject or iterable of- typeobjects used to indicate which types are allowed. The first (or only) item in- typeswill indicate the primary type that- valuewill be returned as.
- allow_dict ( - bool) – If- True, will accept a- dictobject as- value. Defaults to- True.
- allow_json ( - bool) – If- True, will accept a- strobject as- value, under the assumption that is is deserializable as JSON. Defaults to- True.
- allow_none ( - bool) – If- True, will accept an empty or- Noneobject as- value. Defaults to- True.
- allow_js_literal ( - bool) – If- True, will accept a- strobject as- value, under the assumption that it is deserializable as a JavaScript object literal. Defaults to- True.
- force_iterable ( - bool) – If- True, will accept an iterable object as- value. Defaults to- False(because most attributes are just singletons).
- function_name ( - str) – The optional name of the function that was originally called.
 
- Types:
- Returns:
- valuede-serialized to the primary type (first- typein- types)
- Return type:
- first - typein- types
- Raises:
- HighchartsImplementationError – if - typesis empty
- HighchartsValueError – if - typesdoes not contain a- typeor iterable of- typeobjects
- HighchartsValueError – if the primary type does not conform to the - HighchartsMetainterface 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') str | None[source]
- Convert - itemto 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'.
 
- Returns:
- A JavaScript object literal code snippet, expressed as a string. Or - Noneif- itemis not serializable.
- Return type:
 
function: attempt_variable_declaration()
function: is_js_function_or_class()
function: get_js_literal()
function: assemble_js_literal()
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 - objand execute their- _to_untrimmed_dict()methods.- Parameters:
- obj ( - HighchartsMeta) – The object to be traversed.
- in_cls ( - typeor- None) – The class from which- mro__to_untrimmed_dict()was called.
 
- Returns:
- Collection of untrimmed - dictrepresentations 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:: 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_datato return a list of- dictobjects, one for each record.- Parameters:
- Returns:
- Collection of column names (or numerical keys) and CSV records as - dictvalues
- Return type: