Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

API

Sync GraphQL POST client. Base class for Info and Exchange.

Use API directly when you need to post a GraphQL document the SDK does not wrap. Most callers should pick Info or Exchange instead.

Setup

from dango.api import API
 
api = API("https://api-mainnet.dango.zone")

Constructor

API(base_url: str, *, timeout: float | None = None) -> None

Configuration

base_urlstr. GraphQL endpoint URL; the suffix /graphql is appended at query time.

timeoutfloat | None, optional. HTTP timeout in seconds applied to every POST. Default: no timeout.

Methods

MethodDescription
queryPOST a GraphQL document and return the data field
query_typedSame as query plus a static cast on the result

query

def query(
    self,
    document: str,
    variables: dict[str, Any] | None = None,
) -> dict[str, Any]

POSTs {"query": document, "variables": variables} to <base_url>/graphql and returns the GraphQL data envelope. Raises:

data = api.query("""
query Status { queryStatus { chainId block { blockHeight } } }
""")
print(data["queryStatus"]["chainId"])

query_typed

def query_typed[T](
    self,
    document: str,
    variables: dict[str, Any] | None = None,
    *,
    response_type: type[T],
) -> T

Same as query but cast(T, ...)s the result. No runtime validation — the cast is for type checkers only.

Notes

  • The class holds a requests.Session for HTTP keep-alive across queries.
  • Content-Type: application/json is set on the session at construction; no need to override per call.
  • Both query and mutation documents go through query() — the GraphQL operation keyword lives inside the document string.

See also