Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.74 KB

querying_horizon.rst

File metadata and controls

40 lines (29 loc) · 1.74 KB

Querying Horizon

py-stellar-sdk gives you access to all the endpoints exposed by Horizon.

Building requests

py-stellar-sdk uses the Builder pattern to create the requests to send to Horizon. Starting with a :pyServer <stellar_sdk.server.Server> object, you can chain methods together to generate a query. (See the Horizon reference documentation for what methods are possible.)

../../examples/query_horizon.py

Once the request is built, it can be invoked with :pycall() <stellar_sdk.call_builder.BaseCallBuilder.call> or with :pystream() <stellar_sdk.call_builder.BaseCallBuilder.stream>. :pycall() <stellar_sdk.call_builder.BaseCallBuilder.call> will return the response given by Horizon.

Streaming requests

Many requests can be invoked with :pystream() <stellar_sdk.call_builder.BaseCallBuilder.stream>. Instead of returning a result like :pycall() <stellar_sdk.call_builder.BaseCallBuilder.call> does, :pystream() <stellar_sdk.call_builder.BaseCallBuilder.stream> will return an EventSource. Horizon will start sending responses from either the beginning of time or from the point specified with :pycursor() <stellar_sdk.call_builder.BaseCallBuilder.cursor>. (See the Horizon reference documentation to learn which endpoints support streaming.)

For example, to log instances of transactions from a particular account:

../../examples/stream_requests.py