stellar-model

GitHub Action Read the Docs PyPI Python - Version

stellar-model is based on pydantic, you can use it to parse the JSON returned by Stellar Horizon into Python models, through it, you can get a better development experience in the editor with things like code completion, type hints, and more.

Installing

You need to choose a suitable stellar-model version according to the Horizon version number you are using. Please check the list here.

pip install stellar-model==0.5.4

Example

import requests
from stellar_model import AccountResponse

url = "https://horizon.stellar.org/accounts/GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = requests.get(url).json()
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")

Of course you can use it with stellar-sdk.

from stellar_sdk import Server
from stellar_model import AccountResponse

server = Server("https://horizon.stellar.org")
account_id = "GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = server.accounts().account_id(account_id).call()
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")

Documentation

stellar-model’s documentation can be found at https://stellar-model.readthedocs.io

API Reference

Response Model

AccountDataResponse

class stellar_model.response.AccountDataResponse(*, value: str, sponsor: str | None = None)[source]

Represents single account data response.

Can be used for the following endpoint(s):

  • GET /accounts/:account_id/data/:key

See Retrieve an Account’s Data on Stellar API Reference.

AccountResponse

class stellar_model.response.AccountResponse(*, id: str, account_id: str, sequence: int, sequence_ledger: int | None = None, sequence_time: datetime | None = None, subentry_count: int, inflation_destination: str | None = None, home_domain: str | None = None, last_modified_ledger: int, last_modified_time: datetime | None = None, thresholds: AccountThresholds, flags: AccountFlags, balances: List[Balance], signers: List[Signer], data: Mapping[str, str], num_sponsoring: int, num_sponsored: int, sponsor: str | None = None, paging_token: str, _links: Links)[source]

Represents single account response.

Can be used for the following endpoint(s):

  • GET /accounts/:account_id

See Retrieve an Account on Stellar API Reference.

AccountsResponse

class stellar_model.response.AccountsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents accounts response.

Can be used for the following endpoint(s):

  • GET /accounts

See Accounts on Stellar API Reference.

AssetsResponse

class stellar_model.response.AssetsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents assets response.

Can be used for the following endpoint(s):

  • GET /accounts

See Assets on Stellar API Reference.

ClaimableBalanceResponse

class stellar_model.response.ClaimableBalanceResponse(*, id: str, asset: str, amount: Decimal, sponsor: str | None = None, last_modified_ledger: int, last_modified_time: datetime | None = None, claimants: List[Claimant], flags: ClaimableBalanceFlags, paging_token: str, _links: Links)[source]

Represents single claimable balance response.

Can be used for the following endpoint(s):

  • GET /claimable_balances/:claimable_balance_id

See Claimable Balances on Stellar API Reference.

ClaimableBalancesResponse

class stellar_model.response.ClaimableBalancesResponse(*, _links: Links, _embedded: Embedded)[source]

Represents claimable balances response.

Can be used for the following endpoint(s):

  • GET /claimable_balances

See Claimable Balances on Stellar API Reference.

EffectsResponse

class stellar_model.response.EffectsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents effects response.

Can be used for the following endpoint(s):

  • GET /effects

See Effects on Stellar API Reference.

ErrorResponse

class stellar_model.response.ErrorResponse(*, type: str, title: str, status: int, detail: str | None = None, extras: Mapping[str, Any] | None = None)[source]

Represents error response.

See Error Response on Stellar API Reference.

FeeStatsResponse

class stellar_model.response.FeeStatsResponse(*, last_ledger: int, last_ledger_base_fee: int, ledger_capacity_usage: Decimal, fee_charged: FeeDistribution, max_fee: FeeDistribution)[source]

Represents fee stats response.

Can be used for the following endpoint(s):

  • GET /fee_stats

See Fee Stats on Stellar API Reference.

LedgerResponse

class stellar_model.response.LedgerResponse(*, id: str, paging_token: str, hash: str, prev_hash: str | None = None, sequence: int, successful_transaction_count: int, failed_transaction_count: int, operation_count: int, tx_set_operation_count: int, closed_at: datetime, total_coins: Decimal, fee_pool: Decimal, base_fee_in_stroops: int, base_reserve_in_stroops: int, max_tx_set_size: int, protocol_version: int, header_xdr: str, _links: Links)[source]

Represents single ledger response.

Can be used for the following endpoint(s):

  • GET /ledger/:sequence_id

See Retrieve a Ledger on Stellar API Reference.

LedgersResponse

class stellar_model.response.LedgersResponse(*, _links: Links, _embedded: Embedded)[source]

Represents ledgers response.

Can be used for the following endpoint(s):

  • GET /ledgers

See Ledgers on Stellar API Reference.

LiquidityPoolResponse

class stellar_model.response.LiquidityPoolResponse(*, id: str, paging_token: str, fee_bp: int, type: str, total_trustlines: int, total_shares: Decimal, reserves: List[LiquidityPoolAssetAmount], last_modified_ledger: int, last_modified_time: datetime | None = None, _links: Links)[source]

Represents single liquidity pool response.

Can be used for the following endpoint(s):

  • GET /liquidity_pools/:liquidity_pool_id

See Retrieve a Liquidity Pool on Stellar API Reference.

LiquidityPoolsResponse

class stellar_model.response.LiquidityPoolsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents liquidity pools response.

Can be used for the following endpoint(s):

  • GET /liquidity_pools

See Liquidity Pools on Stellar API Reference.

OfferResponse

class stellar_model.response.OfferResponse(*, id: str, paging_token: str, seller: str, selling: Asset, buying: Asset, amount: Decimal, price_r: Price, price: Decimal, last_modified_ledger: int, last_modified_time: datetime | None = None, sponsor: str | None = None, _links: Links)[source]

Represents single offer response.

Can be used for the following endpoint(s):

  • GET /offer/:offer_id

See Retrieve an Offer on Stellar API Reference.

OffersResponse

class stellar_model.response.OffersResponse(*, _links: Links, _embedded: Embedded)[source]

Represents offers response.

Can be used for the following endpoint(s):

  • GET /offers

See Offers on Stellar API Reference.

OperationResponse

class stellar_model.response.OperationResponse(*, record: CreateAccountOperation | PaymentOperation | PathPaymentStrictReceiveOperation | ManageSellOfferOperation | CreatePassiveSellOfferOperation | SetOptionsOperation | ChangeTrustOperation | AllowTrustOperation | AccountMergeOperation | InflationOperation | ManageDataOperation | BumpSequenceOperation | ManageBuyOfferOperation | PathPaymentStrictSendOperation | CreateClaimableBalanceOperation | ClaimClaimableBalanceOperation | BeginSponsoringFutureReservesOperation | EndSponsoringFutureReservesOperation | RevokeSponsorshipOperation | ClawbackOperation | ClawbackClaimableBalanceOperation | SetTrustLineFlagsOperation | LiquidityPoolDepositOperation | LiquidityPoolWithdrawOperation | InvokeHostFunctionOperation | BumpFootprintExpirationOperation | RestoreFootprintOperation)[source]

Represents single operation response.

Can be used for the following endpoint(s):

  • GET /operations/:operation_id

See Operations on Stellar API Reference.

OperationsResponse

class stellar_model.response.OperationsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents operations response.

Can be used for the following endpoint(s):

  • GET /operations

See Operations on Stellar API Reference.

PathsResponse

class stellar_model.response.PathsResponse(*, _embedded: Embedded)[source]

Represents paths response.

Can be used for the following endpoint(s):

  • GET /paths/strict-receive

  • GET /paths/strict-send

See Paths on Stellar API Reference.

PaymentsResponse

class stellar_model.response.PaymentsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents payments response.

Can be used for the following endpoint(s):

  • /payments{?cursor,limit,order,include_failed}

RootResponse

class stellar_model.response.RootResponse(*, horizon_version: str, core_version: str, ingest_latest_ledger: int, history_latest_ledger: int, history_latest_ledger_closed_at: datetime, history_elder_ledger: int, core_latest_ledger: int, network_passphrase: str, current_protocol_version: int, core_supported_protocol_version: int, _links: Links)[source]

Represents root response.

Can be used for the following endpoint(s):

  • GET /root

TradeAggregationsResponse

class stellar_model.response.TradeAggregationsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents trade aggregations response.

Can be used for the following endpoint(s):

  • GET /trade_aggregations

See Trade Aggregations on Stellar API Reference.

TradesResponse

class stellar_model.response.TradesResponse(*, _links: Links, _embedded: Embedded)[source]

Represents trades response.

Can be used for the following endpoint(s):

  • GET /trades

See Trades on Stellar API Reference.

TransactionResponse

class stellar_model.response.TransactionResponse(*, id: str, paging_token: str, successful: bool, hash: str, ledger: int, created_at: datetime, source_account: str, account_muxed: str | None = None, account_muxed_id: int | None = None, source_account_sequence: int, fee_account: str, fee_account_muxed: str | None = None, fee_account_muxed_id: int | None = None, fee_charged: int, max_fee: int, operation_count: int, envelope_xdr: str, result_xdr: str, result_meta_xdr: str, fee_meta_xdr: str, memo_type: str, memo: str | None = None, memo_bytes: bytes | None = None, signatures: List[str], valid_after: datetime | None = None, valid_before: datetime | None = None, preconditions: TransactionPreconditions | None = None, fee_bump_transaction: FeeBumpTransaction | None = None, inner_transaction: InnerTransaction | None = None, _links: Links)[source]

Represents single transaction response.

Can be used for the following endpoint(s):

  • GET /transactions/:transaction_id

  • POST /transactions

See Transactions on Stellar API Reference.

TransactionsResponse

class stellar_model.response.TransactionsResponse(*, _links: Links, _embedded: Embedded)[source]

Represents transactions response.

Can be used for the following endpoint(s):

  • GET /transactions

See Transactions on Stellar API Reference.