Files
prime-sdk-python/prime_sdk/__init__.py
Andrew Miller 7b1e9f6309
All checks were successful
Publish to PyPI Registry / publish (release) Successful in 1m14s
Add proof-measure client + Gitea PyPI publish; bump to 0.4.0
proof-measure is a separate, public, unauthenticated Dragonchain service. Adds:
- UnauthenticatedClient: HMAC-free transport mirroring Client (session
  injection, allow_redirects=False, from_dict decoding).
- ProofMeasureClient: get_security / report / health; default base URL
  https://proof-measure.dragonchain.com. Standalone (ProofMeasureClient()) and
  via DragonchainSDK.proof_measure.
- Proof-measure dataclass models (decimals as strings, timestamps as int).
- .gitea/workflows/publish.yml: build + twine upload to the Gitea PyPI registry
  on release (the SDK had no publish workflow before).

Also fixes 3 pre-existing failing tests: _FakeSession.request didn't accept the
allow_redirects kwarg the client now passes (added by the prior redirect change),
so the suite was red at HEAD.
2026-06-04 13:53:16 -04:00

188 lines
5.4 KiB
Python

"""Python SDK for interacting with Dragonchain (Prime) nodes.
Example — fire and forget (most use cases)::
from prime_sdk import DragonchainSDK, TransactionCreateRequest
client = DragonchainSDK(
"your-public-id",
"your-auth-key-id",
"your-auth-key",
"https://your-dragonchain-endpoint.com",
)
resp = client.transaction.create(
TransactionCreateRequest(
txn_type="my-transaction-type",
payload='{"message": "Hello Dragonchain"}',
)
)
print("Transaction ID:", resp.transaction_id)
# Done — no need to wait for a block.
Example — wait for block inclusion (interchain / Daria)::
import time
resp = client.transaction.create(
TransactionCreateRequest(
txn_type="my-transaction-type",
payload='{"message": "Hello Dragonchain"}',
)
)
while True:
txn = client.transaction.get(resp.transaction_id)
if txn.header.block_id:
print("Block ID:", txn.header.block_id)
break
time.sleep(2)
"""
from .block import BlockClient
from .client import CONTENT_TYPE_JSON, Client
from .contract import ContractClient
from .errors import DragonchainAPIError, DragonchainError
from .models import (
Block,
BlockHeader,
BlockProof,
GrpcConnectionInfo,
InterchainTrace,
InterchainTransaction,
ListResponse,
ListTransactionsResponse,
SmartContract,
SmartContractCreateRequest,
SmartContractExecutionInfo,
SmartContractUpdateRequest,
SuccessResponse,
SystemStatus,
Transaction,
TransactionBulkRequest,
TransactionBulkResponse,
TransactionCreateRequest,
TransactionCreateResponse,
TransactionHeader,
TransactionListResponse,
TransactionProof,
TransactionType,
TransactionTypeCreateRequest,
TransactionTypeCreateResponse,
VerificationBlock,
)
from .models import (
AnchorSecurity,
HashPower,
HealthResponse,
RawMeasure,
ReportAnchorInput,
ReportRequest,
SecurityResult,
TransactionReport,
)
from .proof_measure import DEFAULT_BASE_URL as PROOF_MEASURE_DEFAULT_BASE_URL
from .proof_measure import ProofMeasureClient
from .system import SystemClient
from .transaction import TransactionClient
from .transaction_type import TransactionTypeClient
from .unauthenticated_client import UnauthenticatedClient
__version__ = "0.4.0"
class DragonchainSDK:
"""Main SDK client for interacting with Dragonchain nodes.
Provides access to all API endpoints through specialized client instances:
``system``, ``transaction``, ``transaction_type``, ``contract``, ``block``.
"""
def __init__(
self,
public_id: str,
auth_key_id: str,
auth_key: str,
base_url: str,
session: "Optional[requests.Session]" = None,
):
"""Create a new Dragonchain SDK client.
Args:
public_id: Your Dragonchain public ID.
auth_key_id: Your authentication key ID.
auth_key: Your authentication key.
base_url: Base URL of your node (e.g. "https://chains.dragonchain.com").
session: Optional pre-configured ``requests.Session``. Inject one
with an SSRF-guarded transport adapter when ``base_url`` is
attacker-influenced (a tenant's prime_endpoint); the default
session is unguarded and intended for trusted/CLI use.
"""
self._client = Client(public_id, auth_key_id, auth_key, base_url, session=session)
self.transaction = TransactionClient(self._client)
self.transaction_type = TransactionTypeClient(self._client)
self.contract = ContractClient(self._client)
self.block = BlockClient(self._client)
self.system = SystemClient(self._client)
# proof-measure is a separate, unauthenticated public service; this
# handle targets its default public endpoint. For a custom endpoint
# construct a ``ProofMeasureClient`` directly.
self.proof_measure = ProofMeasureClient()
def get_client(self) -> Client:
"""Return the underlying HTTP client (advanced use)."""
return self._client
__all__ = [
"DragonchainSDK",
"Client",
"CONTENT_TYPE_JSON",
"DragonchainError",
"DragonchainAPIError",
"BlockClient",
"ContractClient",
"SystemClient",
"TransactionClient",
"TransactionTypeClient",
"ProofMeasureClient",
"UnauthenticatedClient",
"PROOF_MEASURE_DEFAULT_BASE_URL",
# models
"Block",
"BlockHeader",
"BlockProof",
"GrpcConnectionInfo",
"InterchainTrace",
"InterchainTransaction",
"ListResponse",
"ListTransactionsResponse",
"SmartContract",
"SmartContractCreateRequest",
"SmartContractExecutionInfo",
"SmartContractUpdateRequest",
"SuccessResponse",
"SystemStatus",
"Transaction",
"TransactionBulkRequest",
"TransactionBulkResponse",
"TransactionCreateRequest",
"TransactionCreateResponse",
"TransactionHeader",
"TransactionListResponse",
"TransactionProof",
"TransactionType",
"TransactionTypeCreateRequest",
"TransactionTypeCreateResponse",
"VerificationBlock",
# proof-measure models
"RawMeasure",
"SecurityResult",
"ReportAnchorInput",
"ReportRequest",
"AnchorSecurity",
"HashPower",
"TransactionReport",
"HealthResponse",
]