xia_compiler_python.compiler.PythonCompiler

class xia_compiler_python.compiler.PythonCompiler

Bases: object

__init__()

Methods

__init__()

ast_to_dict(node)

Parsed AST to python dictionary

code_to_dict(code)

Python Source Code to python dictionary

data_model_to_dict(model_name, base_name[, ...])

dict_to_ast(node_dict)

Reconstruct AST by using node dictionary

dict_to_code(tree_dict)

python dictionary convert back to Python Source Code

embedded_field_to_dict(field_name, ...)

field_parameters_to_dict(field_parameters)

generate_model(model_name, base_name, ...[, ...])

Generate code structure dictionary for a given model

generate_python(model_name, json_schema[, ...])

Using json schema and json data to reconstruct data model

get_field_parameters(field_schema)

list_embedded_field_to_dict(field_name, ...)

list_field_to_dict(field_name, field_class, ...)

module_to_dict()

simple_field_to_dict(field_name, ...)

Attributes

field_dict

classmethod ast_to_dict(node)

Parsed AST to python dictionary

Parameters

node – AST node

Returns:

classmethod code_to_dict(code: str) dict

Python Source Code to python dictionary

Parameters

code – source code of model

Returns

dictionary of parsed code

classmethod dict_to_ast(node_dict: dict)

Reconstruct AST by using node dictionary

Parameters

node_dict – dictionary of node descriptions

Returns

AST Tree

classmethod dict_to_code(tree_dict: dict) str

python dictionary convert back to Python Source Code

Parameters

tree_dict – AST in dictionary mode

Returns

source code

classmethod generate_model(model_name: str, base_name: str, json_schema: dict, is_embedded: bool = False, key_fields: Optional[list] = None) dict

Generate code structure dictionary for a given model

Parameters
  • model_name – Model Name

  • base_name – Parent Class Name, typically Document or EmbeddedDocument

  • json_schema – json schema

  • is_embedded – Is embedded

  • key_fields – key fields list

Returns

Code structure dictionary

classmethod generate_python(model_name: str, json_schema: dict, key_fields: Optional[list] = None) str

Using json schema and json data to reconstruct data model

Parameters
  • model_name – Name of Model

  • json_schema – Json schema definition

  • key_fields – key fields list: * Value None = auto-generate key fields (1 items of json schema) * Value [] = no key fields

Returns

Python code