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]]) BM

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]) BM

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.

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(*args: List[Any], **kwargs: Dict[str, Any])

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
class xrpl.models.response.ResponseStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

Represents the different status possibilities.

ERROR = 'error'
SUCCESS = 'success'
class xrpl.models.response.ResponseType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

Represents the different response types a Response can have.

LEDGER_CLOSED = 'ledgerClosed'
RESPONSE = 'response'
TRANSACTION = 'transaction'

Exceptions

General XRPL Model Exceptions.

exception xrpl.models.exceptions.XRPLModelException

Bases: XRPLException

General XRPL Model Exception.