sbv2-solana/python/switchboardpy
dependabot[bot] 59dde86d96
build(deps): bump certifi in /python/switchboardpy
Bumps [certifi](https://github.com/certifi/python-certifi) from 2021.10.8 to 2022.12.7.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2021.10.08...2022.12.07)

---
updated-dependencies:
- dependency-name: certifi
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-07 23:49:12 +00:00
..
switchboardpy removed monorepo structure 2022-09-28 14:37:26 -06:00
tests removed monorepo structure 2022-09-28 14:37:26 -06:00
LICENSE removed monorepo structure 2022-09-28 14:37:26 -06:00
README.md removed monorepo structure 2022-09-28 14:37:26 -06:00
example.py removed monorepo structure 2022-09-28 14:37:26 -06:00
poetry.lock build(deps): bump certifi in /python/switchboardpy 2022-12-07 23:49:12 +00:00
pyproject.toml build(deps): bump certifi in /python/switchboardpy 2022-12-07 23:49:12 +00:00
switchboard_v2.devnet.parsed.json removed monorepo structure 2022-09-28 14:37:26 -06:00
switchboard_v2.mainnet.parsed.json removed monorepo structure 2022-09-28 14:37:26 -06:00

README.md

switchboardv2-py-api


SwitchboardPy is the Python client for Switchboard. It provides wrappers to help you to interact with the Switchboard V2 program on-chain.

Internally it uses AnchorPy, an Anchor API implementation in Python.

pypi   twitter  

Installation

pip install switchboardpy

Basic Usage

import asyncio
from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.rpc.async_api import AsyncClient
from anchorpy import Program, Provider, Wallet

from switchboardpy import AggregatorAccount, AccountParams

# Devnet Program ID.
SBV2_DEVNET_PID = PublicKey(
    '2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG'
)

async def main():
    client = AsyncClient("https://api.devnet.solana.com/")
    provider = Provider(client, Wallet(Keypair()))
    program = await Program.at(
        SBV2_DEVNET_PID, provider
    )
    agg = AggregatorAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))

    # getting aggregator data
    data = await agg.load_data()

    # getting most recent value (decimal.Decimal)
    val = await agg.get_latest_value()

    print('LATEST VALUE:')
    print(val)

    await program.close()

asyncio.run(main())

"""
OUTPUT
LATEST VALUE:
180.12115
"""

Anchorpy Client Gen

anchorpy client-gen ./switchboard_v2.mainnet.parsed.json ./switchboardpy --program-id SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f