Data Types¶
DataType¶
-
class
panda_core_data.data_type.
DataType
(*args, **kwargs)¶ Base for all the model types, be it template or model
Internally it uses the TinyDB database
-
__exit__
(*_)¶ Save fields instance into the raw
-
__getattr__
(attr_name)¶ This is here just to make this method back to the default that was overwritten by TinyDB
Parameters: name – name of the attribute to get Return type: Any
-
__iter__
()¶ Iter over all documents from default table.
-
__len__
()¶ Get the total number of documents in the default table.
>>> db = TinyDB('db.json') >>> len(db) 0
Return type: int
-
static
__new__
(cls, *_, db_file=None, **__)¶ Method that handles the instancing of the models and templates, this is necessary because dataclasses create a custom __init__ method. Which we doesn’t use at all if a raw file is supplied.
-
__setattr__
¶ Implement setattr(self, name, value).
-
static
_add_into
(data_type, data_type_dict, **kwargs)¶ You can use the prefix dataclass_ with a dataclass parameter to configure it. They can be found in this link: https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass
For example:
from panda_core_data.model import Model class ModelName(Model, dataclass_init=False): out: int def __init__(self, num): self.out = num ** num
Will make the library not create a __init__ method and use yours instead.
Parameters:
-
add_dependencies
()¶ Add all dependencies for the model
-
has_dependencies
¶ If the model has any dependencies
Return type: bool
Returns: If the instance have dependencies or not.
-
keys
()¶ Iter over all documents from default table.
-
load_db
(db_file, *init_args, default_table='data', **kwargs)¶ Method that load raw files and assign each field to an attribute.
Parameters: - db_file (
Union
[Path
,str
]) – Path to a raw file - storage (tinydb.storages.Storage) – storage class to be used.
- default_table (
str
) – default main field in the raw file.
- db_file (
-
save_to_file
(*_)¶ Save fields instance into the raw
-
Model¶
-
class
panda_core_data.model.
Model
(*args, **kwargs)¶ Bases:
panda_core_data.data_type.DataType
-
classmethod
__init_subclass__
(core_name=None, **kwargs)¶ Method that automatically registers class types into data_core. You can use the same parameters as
_add_into()
-
classmethod
Template¶
-
class
panda_core_data.model.
Template
(*args, **kwargs)¶ Bases:
panda_core_data.data_type.DataType
Class that will be used to make ModelTemplates
-
classmethod
__init_subclass__
(core_name=None, **kwargs)¶ Method that automatically registers class types into data_core. You can use the same parameters as
_add_into()
-
classmethod