XRPL Models
Use these classes to validate the formats for all types of data coming from or going to the XRP Ledger.
Base Model
The base class for all model types.
- class xrpl.models.base_model.BaseModel
Bases:
ABC
The base class for all model types.
- classmethod from_dict(value: Dict[str, str | int | List[Any] | Dict[str, Any]]) Self
Construct a new BaseModel from a dictionary of parameters.
- Parameters:
value – The value to construct the BaseModel from.
- Returns:
A new BaseModel object, constructed using the given parameters.
- Raises:
XRPLModelException – If the dictionary provided is invalid.
- classmethod from_xrpl(value: str | Dict[str, Any]) Self
Creates a BaseModel object based on a JSON-like dictionary of keys in the JSON format used by the binary codec, or an actual JSON string representing the same data.
- Parameters:
value – The dictionary or JSON string to be instantiated.
- Returns:
A BaseModel object instantiated from the input.
- classmethod is_dict_of_model(dictionary: Any) bool
Checks whether the provided
dictionary
is a dictionary representation of this class.Note: This only checks the exact model, and does not count model inheritance. This method returns
False
if the dictionary represents a subclass of this class.- Parameters:
dictionary – The dictionary to check. Note: The input dictionary can be of non-dict type. For instance, a str representation of JSON.
- Returns:
True if dictionary is a
dict
representation of an instance of this class; False if not.
- is_valid() bool
Returns whether this BaseModel is valid.
- Returns:
Whether this BaseModel is valid.
- to_dict() Dict[str, Any]
Returns the dictionary representation of a BaseModel.
If not overridden, returns the object dict with all non-None values.
- Returns:
The dictionary representation of a BaseModel.
- validate() None
Raises if this object is invalid.
- Raises:
XRPLModelException – if this object is invalid.
Response Model
The base class for all network response types.
Represents fields common to all response types.
- class xrpl.models.response.Response(*, status: ~xrpl.models.response.ResponseStatus = <object object>, result: ~typing.Dict[str, ~typing.Any] = <object object>, id: int | str | None = None, type: ~xrpl.models.response.ResponseType | None = None)
Bases:
BaseModel
The base class for all network response types.
Represents fields common to all response types.
- contains_partial_payment() bool
Returns whether the request contains at least one transactions with the partial payment flag set.
- Returns:
True if at least one transaction in this Response has the partial payment flag set. False otherwise.
- id: int | str | None = None
- is_successful() bool
Returns whether the request was successfully received and understood by the server.
- Returns:
Whether the request was successfully received and understood by the server.
- result: Dict[str, Any]
This field is required.
- status: ResponseStatus
This field is required.
- type: ResponseType | None = None
Exceptions
General XRPL Model Exceptions.
- exception xrpl.models.exceptions.XRPLModelException
Bases:
XRPLException
General XRPL Model Exception.