solsystem


Namesolsystem JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
SummaryType-safe Solana RPC http/websocket API with a focus on Helius and built on Pydantic models.
upload_time2024-08-25 22:18:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords solana blockchain web3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SolSystem

Friendly Solana RPC API client supporting both Http and Websockets. 

Includes some endpoints specific only to Helius and the Metaplex DAAS API for
retrieving asset data.


## Why + Plans
After trying the official solana python + solders packages I was left feeling like they were an afterthought of development and weren't supported too well. The API wasn't to my liking so I decided to develop something more pythonic and cleaner.

As I work on solana projects I plan to add further functionality to this API. One of the goals is to integrate a DEX API as well, likely from jupiter.


## Version Note

This API was built with Python 3.12 and the latest package versions available at the time. The purpose was to take advantage of the great typing additions that have come to python and pydantic up to version 3.12. The library can fairly easily be backported to earlier versions of python, but it was not in the current scope of the author's work. 


## Examples

Using the `SyncClient` to return account info for a particular public key. Common configuration parameters are provided via the Configuration Object. The response object here will be a fully typed solsystem Response object with populated fields.

```python
from SolSystem import (
    SyncClient,
    GetAccountInfo,
    Configuration,
    Encoding,
)
def main():
    with SyncClient(rpc_endpoint = "<RPC ENDPOINT URL>") as client:
        response = client.request(
            method = GetAccountInfo(
                account = "<BASE58 PUBLIC KEY>",
                configuration = Configuration(
                    encoding = Encoding.JSONPARSED,
                )
            )
        )
        # Note response is fully typed as a Response[Account] object
        print(response.model_dump_json(indent = 2))
```


Here we use the `AsyncClient` to get the current account balance and display the balance in both SOL and Lamports. We can use the Lamports response object to easily convert and perform arithmetic operations on the value.

```python
import asyncio
from SolSystem import (
    AsyncClient,
    GetAccountBalance,
    Configuration,
    Commitment,
)
async def main():
    async with AsyncClient(rpc_endpoint = "<RPC ENDPOINT URL>") as client:
        resopnse = await client.request(
            method = GetAccountBalance(
                account = "<BASE58 PUBLIC KEY>",
                configuration = Configuration(
                    commitment = Commitment.CONFIRMED,
                )
            )
        )
        # Note response is fully typed as a Response[Lamports] object
        print(response.model_dump_json(indent = 2))

        print(F"Lamport Value: {response.value}")
        print(F"Sol Value: {response.value.sol}")
```

The `Websocket` client works as a factory which creates subscribed clients. Each call to `subscribe` on the factory will create a sepearte object that manages the subscription for its specific method. We then use an async iterator or a loop to recieve messages on each subscription.


```python
import asyncio
from SolSystem import (
    WebsocketClient,
    WsGetAccountInfo,
    Configuration,
    Commitment,
)
async def main():
    async with WebsocketClient(
            end_point = "<WS RPC ENDPOINT URL>",
            message_limit = 3,
    ) as client_factory:
        # We will only recieve 3 messages per subscription
        account_subscription = await client_factory.subscribe(
            method = WsGetAccountInfo(
                account = "<BASE58 PUBLIC KEY>",
                configuration = Configuration(
                    commitment = Commitment.FINALIZED,
                )
            )
        )

        async for message in account_subscription:
            print(F"Owner: {message.value.owner}")
            print(F"Balance: {message.value.lamports}")
            print(F"Data: {message.value.data}")
            
        await account_subscription.unsubscribe()
```


## Development

The project uses `pdm` as both the package manager and the build tool for simplicity. For development simply pull and run `pdm install` provided you have the correct python version and pdm installed already.

Simple tests are available in the `/tests/` folder for confirming that response and request models are working correctly.

The project was developed in an environment running ruff and pylance so type checking was done through them.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "solsystem",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "solana, blockchain, web3",
    "author": null,
    "author_email": "Aleksandr Grin <bytebrushsoftware@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/97/50/6178996bf887e92de9e60ea2ad1228749df41d67d471ee280e592305032c/solsystem-1.0.3.tar.gz",
    "platform": null,
    "description": "# SolSystem\n\nFriendly Solana RPC API client supporting both Http and Websockets. \n\nIncludes some endpoints specific only to Helius and the Metaplex DAAS API for\nretrieving asset data.\n\n\n## Why + Plans\nAfter trying the official solana python + solders packages I was left feeling like they were an afterthought of development and weren't supported too well. The API wasn't to my liking so I decided to develop something more pythonic and cleaner.\n\nAs I work on solana projects I plan to add further functionality to this API. One of the goals is to integrate a DEX API as well, likely from jupiter.\n\n\n## Version Note\n\nThis API was built with Python 3.12 and the latest package versions available at the time. The purpose was to take advantage of the great typing additions that have come to python and pydantic up to version 3.12. The library can fairly easily be backported to earlier versions of python, but it was not in the current scope of the author's work. \n\n\n## Examples\n\nUsing the `SyncClient` to return account info for a particular public key. Common configuration parameters are provided via the Configuration Object. The response object here will be a fully typed solsystem Response object with populated fields.\n\n```python\nfrom SolSystem import (\n    SyncClient,\n    GetAccountInfo,\n    Configuration,\n    Encoding,\n)\ndef main():\n    with SyncClient(rpc_endpoint = \"<RPC ENDPOINT URL>\") as client:\n        response = client.request(\n            method = GetAccountInfo(\n                account = \"<BASE58 PUBLIC KEY>\",\n                configuration = Configuration(\n                    encoding = Encoding.JSONPARSED,\n                )\n            )\n        )\n        # Note response is fully typed as a Response[Account] object\n        print(response.model_dump_json(indent = 2))\n```\n\n\nHere we use the `AsyncClient` to get the current account balance and display the balance in both SOL and Lamports. We can use the Lamports response object to easily convert and perform arithmetic operations on the value.\n\n```python\nimport asyncio\nfrom SolSystem import (\n    AsyncClient,\n    GetAccountBalance,\n    Configuration,\n    Commitment,\n)\nasync def main():\n    async with AsyncClient(rpc_endpoint = \"<RPC ENDPOINT URL>\") as client:\n        resopnse = await client.request(\n            method = GetAccountBalance(\n                account = \"<BASE58 PUBLIC KEY>\",\n                configuration = Configuration(\n                    commitment = Commitment.CONFIRMED,\n                )\n            )\n        )\n        # Note response is fully typed as a Response[Lamports] object\n        print(response.model_dump_json(indent = 2))\n\n        print(F\"Lamport Value: {response.value}\")\n        print(F\"Sol Value: {response.value.sol}\")\n```\n\nThe `Websocket` client works as a factory which creates subscribed clients. Each call to `subscribe` on the factory will create a sepearte object that manages the subscription for its specific method. We then use an async iterator or a loop to recieve messages on each subscription.\n\n\n```python\nimport asyncio\nfrom SolSystem import (\n    WebsocketClient,\n    WsGetAccountInfo,\n    Configuration,\n    Commitment,\n)\nasync def main():\n    async with WebsocketClient(\n            end_point = \"<WS RPC ENDPOINT URL>\",\n            message_limit = 3,\n    ) as client_factory:\n        # We will only recieve 3 messages per subscription\n        account_subscription = await client_factory.subscribe(\n            method = WsGetAccountInfo(\n                account = \"<BASE58 PUBLIC KEY>\",\n                configuration = Configuration(\n                    commitment = Commitment.FINALIZED,\n                )\n            )\n        )\n\n        async for message in account_subscription:\n            print(F\"Owner: {message.value.owner}\")\n            print(F\"Balance: {message.value.lamports}\")\n            print(F\"Data: {message.value.data}\")\n            \n        await account_subscription.unsubscribe()\n```\n\n\n## Development\n\nThe project uses `pdm` as both the package manager and the build tool for simplicity. For development simply pull and run `pdm install` provided you have the correct python version and pdm installed already.\n\nSimple tests are available in the `/tests/` folder for confirming that response and request models are working correctly.\n\nThe project was developed in an environment running ruff and pylance so type checking was done through them.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Type-safe Solana RPC http/websocket API with a focus on Helius and built on Pydantic models.",
    "version": "1.0.3",
    "project_urls": {
        "Source": "https://github.com/agrin96/solsystem"
    },
    "split_keywords": [
        "solana",
        " blockchain",
        " web3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f561ff256d3d0999e06ca81b13df925e9923201e09872c4588ce860628b70d58",
                "md5": "9f39d64621bd94697caf01ef5885275e",
                "sha256": "c8010fab71a11e08f2dc0e62888c72065a178a542f3b86433a050a66801ea33f"
            },
            "downloads": -1,
            "filename": "solsystem-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f39d64621bd94697caf01ef5885275e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 114744,
            "upload_time": "2024-08-25T22:18:39",
            "upload_time_iso_8601": "2024-08-25T22:18:39.274707Z",
            "url": "https://files.pythonhosted.org/packages/f5/61/ff256d3d0999e06ca81b13df925e9923201e09872c4588ce860628b70d58/solsystem-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97506178996bf887e92de9e60ea2ad1228749df41d67d471ee280e592305032c",
                "md5": "02c31137dfafef0aa80ee6776b159018",
                "sha256": "7b39601df377f70bbe41e606d249fed4e1f9673a96adeb95f45e2ab638b4c515"
            },
            "downloads": -1,
            "filename": "solsystem-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "02c31137dfafef0aa80ee6776b159018",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 61235,
            "upload_time": "2024-08-25T22:18:40",
            "upload_time_iso_8601": "2024-08-25T22:18:40.821412Z",
            "url": "https://files.pythonhosted.org/packages/97/50/6178996bf887e92de9e60ea2ad1228749df41d67d471ee280e592305032c/solsystem-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-25 22:18:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "agrin96",
    "github_project": "solsystem",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "solsystem"
}
        
Elapsed time: 3.03220s