GithubHelp home page GithubHelp logo

beingsoso / stellar-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from future-tense/stellar-py

0.0 0.0 0.0 383 KB

Python client library for Stellar

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

stellar-py's Introduction

stellar-py

Python client library for Stellar

PyPI version

Still a work in progress, but usable.

Example usage: sending a payment

import stellar

Generating keys

If you don't have a wallet already, or if you feel a bit paranoid, this is where you need to start.

account, secret = stellar.generate_keypair()

Connecting to a remote server

remote = stellar.Remote('ws://live.stellar.org:9001')

Sending a payment

amount = stellar.Amount(100) # 100 STR
res = remote.send_payment(secret, account, destination, amount)

(NB: Obviously this whole scenario is just fiction, because you can't really do anything with an account that hasn't been funded.)

stellar.Remote

Remote is the primary interface in stellar-py, and this is what you'll be using the most.

remote = stellar.Remote(url, async=False, callback=None)

This creates a Remote object, connected to a stellard server located at url.

If async is True, then all methods that can be asynchronous, by default are so. This can be overridden in the individual method. If asynchronous, they return an aplus promise for further processing, otherwise they return the actual value.

If a callback is provided, network connectivity changes will be communicated to it.

def callback(status):
	if status:
		#	connected to network
	else:
		#	disconnected from network

Getting information about accounts

get_account_currencies(account, async=None, **kwargs)
get_account_info(account, async=None)
get_account_lines(account, async=None, **kwargs)
get_account_offers(account, async=None)

Getting information about order books

get_book_offers(taker_gets, taker_pays, async=None, **kwargs)

Getting information about ledgers

get_ledger(async=None, **kwargs)

Getting information about transactions

get_transaction_entry(tx_hash, ledger_index, async=None)
get_tx(transaction, async=None, **kwargs)
get_tx_history(start, async=None)

Performing transactions

cancel_offer(secret, account, offer_sequence, async=None)
create_offer(secret, account, taker_gets, taker_pays, async=None, **kwargs)
merge_accounts(secret, account, destination, async=None)
send_payment(secret, account, destination, amount, async=None, **kwargs)
set_options(secret, account, async=None, **kwargs)
set_regular_key(secret, account, regular_key, async=None)
set_trust(secret, account, amount, async=None, **kwargs)

Managing subscriptions

subscribe(async=None, **kwargs)
unsubscribe(async=None, **kwargs)
add_callback(tx_type, callback)

Getting paths

get_static_path(source_account, destination_account, destination_amount, async=None)
create_find_path(source_account, destination_account, destination_amount, callback, async=None)
close_find_path(async=None)

Low-level methods

get_fee(async=None)
get_sequence_number(account, async=None)
submit_transaction(tx_blob, async=None)
cancel(promise)

stellar.Amount

Amount is a helper class for dealing with amounts and currencies.

100 STR:

amount = stellar.Amount(100)

100 USD from issuer:

amount = stellar.Amount(100, 'USD', issuer)

Local operations

Everything that can be done locally is done locally. Key pairs are generated locally, for that extra safety, and the transactions are generated and signed locally. No secret keys are sent across the network.

The two key operations are

account, secret = stellar.generate_keypair()
tx_blob = stellar.sign(tx_json, secret)

stellar.transactions

This is where we find the functions to generate all of the different transaction types on the Stellar network. For a description of what the parameters are, and what they do, check the official documentation over at https://www.stellar.org/api/#api-submit. Optional parameters are provided through kwargs. All amounts are in stellar.Amounts

tx_json = account_merge(account, destination, sequence, fee)
tx_json = account_set(account, sequence, fee, **kwargs)
tx_json = offer_cancel(account, offer_sequence, sequence, fee)
tx_json = offer_create(account, taker_gets, taker_pays, sequence, fee, **kwargs)
tx_json = payment(account, destination, amount, sequence, fee, **kwargs)
tx_json = set_regular_key(account, regular_key, sequence, fee)
tx_json = trust_set(account, amount, sequence, fee, **kwargs)

stellar-py's People

Contributors

johansten avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.