Skip to main content

A simple and unofficial SDK for the Platega.io API.

Project description

🟢 Platega Async SDK (Unofficial)

PyPI Python License

🛠️ A modern, unofficial asynchronous Python SDK for the Platega.io API.
Built with httpx and Pydantic for high performance in async applications like aiogram, FastAPI, or Django Ninja.


✨ Features

  • Fully Asynchronous: Built with httpx to be non-blocking and perfect for modern async frameworks.
  • Type-Safe: Strict request/response validation with Pydantic V2 ensures your code is robust.
  • Secure by Default: Includes a helper to verify webhook signatures, protecting you from fake callbacks.
  • Clean API: A minimalistic and intuitive interface for creating transactions, fetching statuses, and getting rates.
  • Robust Error Handling: Clear, custom exceptions for network and API errors.
  • Resource Management: Uses an async context manager (async with) to handle client sessions gracefully.
  • Modern Python: Supports Python 3.8+.

📦 Installation

pip install plategaio

🚀 Quick Start

The client is designed to be used as an asynchronous context manager.

import asyncio
from uuid import uuid4
from plategaio import (
    PlategaAsyncClient,
    CreateTransactionRequest,
    PaymentDetails,
    PlategaAPIError,
)

async def main():
    async with PlategaAsyncClient(
        merchant_id="YOUR_MERCHANT_ID",
        secret="YOUR_SECRET_KEY",
    ) as client:
        try:
            tx_request = CreateTransactionRequest(
                payment_method=2, # SBP
                id=uuid4(),
                payment_details=PaymentDetails(amount=150.50, currency="RUB"),
                description="Order #123",
                return_url="https://your.site/success",
                failed_url="https://your.site/failed",
            )
            tx_response = await client.create_transaction(tx_request)
            print(f"Redirect user to: {tx_response.redirect}")
            
            status = await client.get_transaction_status(tx_response.transaction_id)
            print(f"Transaction status: {status.status}")

            rate = await client.get_rate(
                payment_method=2, 
                currency_from="USDT", 
                currency_to="RUB"
            )
            print(f"Current USDT->RUB rate: {rate.rate}")

        except PlategaAPIError as e:
            print(f"API Error: {e.status_code} - {e.message}")
        except Exception as e:
            print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    asyncio.run(main())

⚠️ Error Handling

The SDK raises clear, specific exceptions:

  • PlategaError: Base exception for the library.
  • PlategaNetworkError: Raised for network issues like timeouts or connection errors.
  • PlategaAPIError: Raised for non-2xx API responses (e.g., 400, 401, 500). It contains status_code, message, and response_body.

Example:

from plategaio import PlategaAPIError, PlategaNetworkError

try:
    # ... your API call
except PlategaAPIError as e:
    print(f"API returned an error: status={e.status_code}, message='{e.message}'")
except PlategaNetworkError as e:
    print(f"A network error occurred: {e}")

📚 API Reference

PlategaAsyncClient

  • async create_transaction(payload: CreateTransactionRequest) -> CreateTransactionResponse
  • async get_transaction_status(transaction_id: str) -> TransactionStatusResponse
  • async get_rate(payment_method: int, currency_from: str, currency_to: str) -> RateResponse
  • async close(): Closes the client session. Called automatically when using async with.

🌍 Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plategaio-1.0.4.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plategaio-1.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file plategaio-1.0.4.tar.gz.

File metadata

  • Download URL: plategaio-1.0.4.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for plategaio-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b1e17f517f159f94bbc914981395801d87d49827b1e8566da76eb6f15ef00c0c
MD5 706c1a74cbead6b6d48c9447924b8421
BLAKE2b-256 2e502899362a08a9ae0a1aec09d9aca22423c38acdd43981c8fca64573d21763

See more details on using hashes here.

File details

Details for the file plategaio-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: plategaio-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for plategaio-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7b87ec0c49b85f0cdcf2ddf9996cfb2658333e12180bb9f23ead90f1acc82ac2
MD5 b38eec6ccf918ec33b01d888e828875e
BLAKE2b-256 542e5cd3ad2cbd85d7fb36386015090a1baaaf72ab9e7776d4847e4308016049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page