stackcoin-python
Python library for the StackCoin API. Provides a typed async REST client and a WebSocket gateway for real-time events.
Install
pip install stackcoin
Requires Python 3.13+. Dependencies: httpx, pydantic>=2, websockets.
Quick start
import asyncio
import stackcoin
async def main():
async with stackcoin.Client(token="...") as client:
me = await client.get_me()
print(f"{me.username}: {me.balance} STK")
events = await client.get_events()
for event in events:
print(f"[{event.type}] {event.data}")
asyncio.run(main())
Gateway (real-time events)
import stackcoin
gateway = stackcoin.Gateway(token="...")
@gateway.on("transfer.completed")
async def on_transfer(event: stackcoin.TransferCompletedEvent):
print(f"Transfer of {event.data.amount} STK from #{event.data.from_id} to #{event.data.to_id}")
@gateway.on("request.accepted")
async def on_accepted(event: stackcoin.RequestAcceptedEvent):
print(f"Request #{event.data.request_id} accepted")
await gateway.connect()
Catching up on missed events
If your bot persists its cursor position and reconnects with a last_event_id,
the server replays up to 100 missed events. If more than 100 were missed, the
join is rejected — pass a client so the Gateway can automatically catch up
via the REST API. Without a client, a TooManyMissedEventsError is raised.
async with stackcoin.Client(token="...") as client:
gateway = stackcoin.Gateway(
token="...",
client=client,
last_event_id=saved_cursor,
on_event_id=lambda eid: save_cursor(eid),
)
@gateway.on("transfer.completed")
async def on_transfer(event: stackcoin.TransferCompletedEvent):
...
await gateway.connect()
Examples
examples/basic_usage.py-- REST client basics (balance, requests, transactions)examples/simple_cli.py-- interactive REPL with live gateway events
Testing
Tests for this library live in the main StackCoin/StackCoin repository as end-to-end tests that boot a real StackCoin server:
cd /path/to/StackCoin/test/e2e/py
uv sync
uv run pytest
The E2E suite covers the REST client, WebSocket gateway, event pagination, and the LuckyPot bot integration.
Development
Models are generated from the StackCoin OpenAPI spec using datamodel-codegen:
STACKCOIN_ROOT=/path/to/StackCoin just generate
This regenerates src/stackcoin/models.py from openapi.json.
Release files for stackcoin 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stackcoin-0.1.6.tar.gz | 23.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stackcoin-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.1 kB
Release files / stackcoin-0.1.6.tar.gz
| Download URL | stackcoin-0.1.6.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
789b2347722f087c42c4e1b34cce9f298d20213695aadbaacc27f8ba2c4164d0
|
|
BLAKE2b-256 checksum How to use checksums |
eb558d06462743c0117993cd7af67e015461e9606d1a17e364bd44516ea12643
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / stackcoin-0.1.6-py3-none-any.whl
| Download URL | stackcoin-0.1.6-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6929b89182529350d6b73badef6633d76ddfe5a74472015b669965b6b8398f71
|
|
BLAKE2b-256 checksum How to use checksums |
2860cf7d554fc4337e08c9a1f5c191f7eb2418a42a7d352ff555b1215e942ea0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|