Classes
- class pyswark.lib.pydantic.base.BaseModel
Enhanced Pydantic BaseModel with serialization capabilities.
This is the standard base class for all models in pyswark. It extends Pydantic’s BaseModel with type-preserving serialization methods that enable “code as data” patterns.
Example
>>> from pyswark.lib.pydantic import base >>> >>> class MyModel(base.BaseModel): ... value: str ... count: int >>> >>> obj = MyModel(value="hello", count=42) >>> json_str = obj.toJson() # Includes type information >>> restored = base.BaseModel.fromJson(json_str) >>> assert type(restored) == MyModel
- static fromDict(*a, **kw)
Reconstruct a model from a dictionary with type information.
- Parameters:
*a – Positional arguments passed to
ser_des.fromDict().**kw – Keyword arguments passed to
ser_des.fromDict().
- Returns:
The reconstructed model instance.
- Return type:
- static fromJson(*a, **kw)
Deserialize JSON to the original model type.
- Parameters:
*a – Positional arguments passed to
ser_des.fromJson().**kw – Keyword arguments passed to
ser_des.fromJson().
- Returns:
The deserialized model instance.
- Return type:
- classmethod getUri()
Get the fully-qualified Python path for this model class.
- Returns:
The module and class name (e.g.,
"mypackage.models.MyModel").- Return type:
str
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- toDict()
Convert this model to a dictionary with embedded type information.
- Returns:
Dictionary with
modelandcontentskeys.- Return type:
dict
- toJson(indent=2, **kw)
Serialize this model to JSON with embedded type information.
- Parameters:
indent (int, optional) – JSON indentation level (default: 2).
**kw – Additional arguments passed to
json.dumps().
- Returns:
JSON string that can be deserialized with
fromJson().- Return type:
str
- write(uri, overwrite=False, indent=2, **kw)
Write the model to a URI location.