stellar-model

GitHub Action Read the Docs PyPI Supported Horizon Version Python - Version PyPI - Implementation

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

pip install stellar-model==0.1.0b1

Example

import requests
from stellar_model import AccountResponse

url = "https://horizon.stellar.org/accounts/GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = requests.get(url).json()
parsed_resp = AccountResponse.parse_obj(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.parse_obj(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)[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, subentry_count: int, inflation_destination: str = None, home_domain: str = None, last_modified_ledger: int, last_modified_time: datetime.datetime, thresholds: stellar_model.model.horizon.account.AccountThresholds, flags: stellar_model.model.horizon.account.AccountFlags, balances: List[stellar_model.model.horizon.account.Balance], signers: List[stellar_model.model.horizon.account.Signer], data: Mapping[str, str], num_sponsoring: int, num_sponsored: int, sponsor: str = None, paging_token: str, _links: stellar_model.model.horizon.account.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.accounts_response.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.assets_response.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.Decimal, sponsor: str = None, last_modified_ledger: int, last_modified_time: datetime.datetime, claimants: List[stellar_model.model.horizon.claimable_balance.Claimant], flags: stellar_model.model.horizon.claimable_balance.ClaimableBalanceFlags, paging_token: str, _links: stellar_model.model.horizon.claimable_balance.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.claimable_balances_response.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.effects_response.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, extras: Mapping[str, Any] = 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.Decimal, fee_charged: stellar_model.model.horizon.fee_stats.FeeDistribution, max_fee: stellar_model.model.horizon.fee_stats.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, sequence: int, successful_transaction_count: int, failed_transaction_count: int, operation_count: int, tx_set_operation_count: int, closed_at: datetime.datetime, total_coins: decimal.Decimal, fee_pool: decimal.Decimal, base_fee_in_stroops: int, base_reserve_in_stroops: int, max_tx_set_size: int, protocol_version: int, header_xdr: str, _links: stellar_model.model.horizon.ledger.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.ledgers_response.Embedded)[source]

Represents ledgers response.

Can be used for the following endpoint(s):

  • GET /ledgers

See Ledgers on Stellar API Reference.

OfferResponse

class stellar_model.response.OfferResponse(*, id: str, paging_token: str, seller: str, selling: stellar_model.model.horizon.asset.Asset, buying: stellar_model.model.horizon.asset.Asset, amount: decimal.Decimal, price_r: stellar_model.model.horizon.price.Price, price: decimal.Decimal, last_modified_ledger: int, last_modified_time: datetime.datetime, sponsor: str = None, _links: stellar_model.model.horizon.offer.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.offers_response.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: Union[stellar_model.model.horizon.operations.CreateAccountOperation, stellar_model.model.horizon.operations.PaymentOperation, stellar_model.model.horizon.operations.PathPaymentStrictReceiveOperation, stellar_model.model.horizon.operations.ManageSellOfferOperation, stellar_model.model.horizon.operations.CreatePassiveSellOfferOperation, stellar_model.model.horizon.operations.SetOptionsOperation, stellar_model.model.horizon.operations.ChangeTrustOperation, stellar_model.model.horizon.operations.AllowTrustOperation, stellar_model.model.horizon.operations.AccountMergeOperation, stellar_model.model.horizon.operations.InflationOperation, stellar_model.model.horizon.operations.ManageDataOperation, stellar_model.model.horizon.operations.BumpSequenceOperation, stellar_model.model.horizon.operations.ManageBuyOfferOperation, stellar_model.model.horizon.operations.PathPaymentStrictSendOperation, stellar_model.model.horizon.operations.CreateClaimableBalanceOperation, stellar_model.model.horizon.operations.ClaimClaimableBalanceOperation, stellar_model.model.horizon.operations.BeginSponsoringFutureReservesOperation, stellar_model.model.horizon.operations.EndSponsoringFutureReservesOperation, stellar_model.model.horizon.operations.RevokeSponsorshipOperation, stellar_model.model.horizon.operations.ClawbackOperation, stellar_model.model.horizon.operations.ClawbackClaimableBalanceOperation, stellar_model.model.horizon.operations.SetTrustLineFlagsOperation])[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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.operations_response.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: stellar_model.response.paths_response.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.payments_response.Embedded)[source]

Represents payments response.

Can be used for the following endpoint(s):

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

TradeAggregationsResponse

class stellar_model.response.TradeAggregationsResponse(*, _links: stellar_model.response.page_model.Links, _embedded: stellar_model.response.trade_aggregations_response.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.trades_response.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.datetime, source_account: str, source_account_sequence: int, fee_account: str, 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, memo_bytes: bytes = None, signatures: List[str], valid_after: datetime.datetime = None, valid_before: datetime.datetime = None, fee_bump_transaction: stellar_model.model.horizon.transaction.FeeBumpTransaction = None, inner_transaction: stellar_model.model.horizon.transaction.InnerTransaction = None, _links: stellar_model.model.horizon.transaction.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: stellar_model.response.page_model.Links, _embedded: stellar_model.response.transactions_response.Embedded)[source]

Represents transactions response.

Can be used for the following endpoint(s):

  • GET /transactions

See Transactions on Stellar API Reference.