### Install glQiwiApi from source Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/installation.rst After cloning the repository, install glQiwiApi using the setup.py script. ```console $ python setup.py install ``` -------------------------------- ### Importing Executor and Starting Polling Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example shows the necessary imports and how to pass the client to the polling functions. ```APIDOC ## Importing Executor and Starting Polling ### Description This snippet illustrates the essential imports from the `glQiwiApi.core.event_fetching.executor` module and how to pass your initialized client object to the polling functions. ### Code Example ```python # Import necessary functions from the executor module from glQiwiApi.core.event_fetching.executor import start_polling, start_webhook # Assume 'client' is your initialized QIWI API client instance # Example of calling the polling function: # await start_polling(client) # or for webhooks: # await start_webhook(client) ``` ``` -------------------------------- ### Starting Polling with Handlers Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example demonstrates how to register handlers and start polling using decorators. ```APIDOC ## Starting Polling with Handlers ### Description This snippet shows the recommended way to register handlers and initiate polling for QIWI API updates using decorators. ### Code Example ```python # Assume 'client' is an initialized QIWI API client instance # Assume 'register_handlers' is a function to register your handlers # Example using decorators for handler registration and starting polling # (Specific decorator usage would depend on the library's implementation) # Placeholder for actual decorator usage and polling start command # For instance, if using a framework that supports this: # @client.on_event('startup') # async def start_polling_handler(): # await start_polling(client) # The actual code would involve importing and calling functions like start_polling # from glQiwiApi.core.event_fetching.executor import start_polling ``` ``` -------------------------------- ### Python QIWI Webhook Example Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/webhooks.rst A basic example demonstrating how to set up a webhook handler in Python for QIWI. ```python from flask import Flask, request app = Flask(__name__) @app.route('/webhook', methods=['POST']) def webhook(): data = request.json print(f'Received webhook data: {data}') # Process the webhook data here return 'Webhook received successfully', 200 if __name__ == '__main__': app.run(port=5000) ``` -------------------------------- ### Running Polling at On_Startup Event with Aiogram Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example shows an alternative method to start QIWI API polling during the aiogram bot's on_startup event. ```APIDOC ## Running Polling at On_Startup Event with Aiogram ### Description This snippet provides an alternative approach to integrating QIWI API polling with aiogram, specifically by initiating the polling process within the `on_startup` event handler of the aiogram bot. ### Code Example ```python # Assume 'client' is your initialized QIWI API client instance # Assume 'dp' is your aiogram Dispatcher instance # Import necessary functions # from glQiwiApi.core.event_fetching.executor import start_polling # @dp.startup_event # async def on_startup(dispatcher: Dispatcher): # # Start QIWI API polling in a non-blocking manner # # asyncio.create_task(start_polling(client)) # pass ``` ``` -------------------------------- ### Install uvloop Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/installation.rst Install uvloop, a faster alternative to the default asyncio event loop, for potential API performance improvements. ```bash $ pip install uvloop ``` -------------------------------- ### Configuring Startup and Shutdown Events Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example demonstrates how to specify functions to be executed on polling startup and shutdown. ```APIDOC ## Configuring Startup and Shutdown Events ### Description This snippet explains how to pass custom functions to `start_polling` that will be executed during the polling process, specifically on startup and shutdown events. ### Parameters #### Request Body (for `start_polling`) - **on_startup** (callable) - Optional - A function to be executed when polling starts. - **on_shutdown** (callable) - Optional - A function to be executed when polling stops. ### Code Example ```python # Assume 'client' is your initialized QIWI API client instance async def my_startup_function(): print("Polling started!") async def my_shutdown_function(): print("Polling stopped!") # Example of calling start_polling with event handlers: # await start_polling( # client, # on_startup=my_startup_function, # on_shutdown=my_shutdown_function # ) ``` ``` -------------------------------- ### Install glQiwiApi using pip Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/installation.rst This is the preferred method for installing the most recent stable release of glQiwiApi. Ensure you have pip installed. ```console $ pip install glQiwiApi ``` -------------------------------- ### Basic Cache Storage Example Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/advanced_features/cache.rst Demonstrates the straightforward usage of InMemoryCacheStorage to store and retrieve a value. By default, it uses UnrealizedCacheInvalidationStrategy. ```python import asyncio from glQiwiApi.core.cache import InMemoryCacheStorage storage = InMemoryCacheStorage() # here is UnrealizedCacheInvalidationStrategy as an invalidation strategy async def cache(): await storage.update(cached=5) cached = await storage.retrieve("cached") print(f"You have cached {cached}") asyncio.run(cache()) ``` -------------------------------- ### Install orjson Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/installation.rst Install orjson, a faster and more correct JSON library for Python, as a replacement for the standard json module to potentially hasten API performance. ```bash $ pip install orjson ``` -------------------------------- ### Create and Check Bill with Middleware Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/usage_with_aiogram.rst This example demonstrates integrating glQiwiApi with aiogram using a custom middleware to inject the QiwiP2PClient into handlers. This approach simplifies client management and access within the aiogram dispatcher. ```python import asyncio import logging from typing import Dict, Any from aiogram import Bot, Dispatcher, types from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.dispatcher import FSMContext from aiogram.dispatcher.middlewares import LifetimeControllerMiddleware from aiogram.types.base import TelegramObject from glQiwiApi import QiwiP2PClient from glQiwiApi.qiwi.clients.p2p.types import Bill BOT_TOKEN = "BOT TOKEN" class EnvironmentMiddleware(LifetimeControllerMiddleware): def __init__(self, qiwi_p2p_client: QiwiP2PClient): super().__init__() self._qiwi_p2p_client = qiwi_p2p_client async def pre_process(self, obj: TelegramObject, data: Dict[str, Any], *args: Any) -> None: data["qiwi_p2p_client"] = self._qiwi_p2p_client async def handle_creation_of_payment( message: types.Message, state: FSMContext, qiwi_p2p_client: QiwiP2PClient ): async with qiwi_p2p_client: bill = await qiwi_p2p_client.create_p2p_bill(amount=1) await message.answer(text=f"Ok, here's your invoice:\n {bill.pay_url}") await state.set_state("payment") await state.update_data(bill=bill) async def handle_successful_payment( message: types.Message, state: FSMContext, qiwi_p2p_client: QiwiP2PClient ): async with state.proxy() as data: bill: Bill = data.get("bill") if await qiwi_p2p_client.check_if_bill_was_paid(bill): await message.answer("You have successfully paid your invoice") await state.finish() else: await message.answer("Invoice was not paid") async def main(): bot = Bot(token=BOT_TOKEN, parse_mode=types.ParseMode.HTML) storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) dp.middleware.setup( EnvironmentMiddleware( qiwi_p2p_client=QiwiP2PClient( secret_p2p="" ) ) ) dp.register_message_handler(handle_creation_of_payment, text="I want to pay") dp.register_message_handler( handle_successful_payment, state="payment", text="I have paid this invoice" ) # start try: await dp.start_polling() finally: await dp.storage.close() await dp.storage.wait_closed() await bot.session.close() logging.basicConfig(level=logging.DEBUG) if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Importing Executor and Client Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst Shows the necessary imports for the executor and passing the client object to it. This is a prerequisite for starting polling or webhooks. ```python from glQiwiApi.core.event_fetching.executor import PollingExecutor executor = PollingExecutor(client=client) ``` -------------------------------- ### Clone glQiwiApi repository Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/installation.rst Clone the development branch of the glQiwiApi repository to get the source files. ```console $ git clone -b dev-2.x git://github.com/GLEF1X/glQiwiApi ``` -------------------------------- ### Example Usage Without Global Variables Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example demonstrates how to use the polling functions without relying on global variables, promoting better code organization. ```APIDOC ## Example Usage Without Global Variables ### Description This snippet illustrates how to manage and initiate QIWI API polling by passing necessary objects and configurations directly, avoiding the use of global variables for a cleaner and more maintainable codebase. ### Code Example ```python # Assume 'client' is your initialized QIWI API client instance # Assume 'configure_app_for_qiwi_webhooks' is a function to set up webhook configurations if needed # Example of setting up and starting polling without global variables: # async def setup_and_start_polling(qiwi_client): # # Perform any necessary setup using qiwi_client # # For example, if webhook configuration is needed: # # await configure_app_for_qiwi_webhooks(qiwi_client) # # # Start polling # await start_polling(qiwi_client) # In your main application logic: # if __name__ == "__main__": # # Initialize your client # # client = YourQiwiApiClient(...) # # Run the setup and start polling function # # asyncio.run(setup_and_start_polling(client)) ``` ``` -------------------------------- ### Polling with Decorators Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst Illustrates the use of decorators for registering handlers and starting polling. Ensure correct imports and emphasize specific lines for handler registration and polling initiation. ```python from glQiwiApi.core.event_fetching.executor import PollingExecutor executor = PollingExecutor(client=client) @executor.polling() def handler(update: Update) -> None: print(update.data) @executor.on_startup() def on_startup_handler() -> None: print("Bot started polling!") @executor.on_shutdown() def on_shutdown_handler() -> None: print("Bot stopped polling!") ``` -------------------------------- ### Simultaneous Polling with Aiogram Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst This example shows how to integrate QIWI API polling with aiogram for handling messages concurrently. ```APIDOC ## Simultaneous Polling with Aiogram ### Description This snippet demonstrates how to run QIWI API polling concurrently with an aiogram bot, allowing you to handle both API updates and Telegram messages within the same application. ### Code Example ```python # Assume 'client' is your initialized QIWI API client instance # Assume 'dp' is your aiogram Dispatcher instance # Example of setting up message handler in aiogram # @dp.message_handler() # async def handle_message(message: types.Message): # await message.reply("Hello") # To run both concurrently, you would typically start them in separate tasks # or use a mechanism that supports running multiple event loops or tasks. # The example in the documentation implies a setup where both can operate. # Placeholder for actual integration code: # async def main(): # # Start aiogram polling # # asyncio.create_task(dp.start_polling()) # # # Start QIWI API polling # # asyncio.create_task(start_polling(client)) # # # Keep the main loop running # # await asyncio.Future() ``` ``` -------------------------------- ### Fetch YooMoney Operation History Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Fetches the operation history for a YooMoney account using an API access token. This example demonstrates how to initialize the YooMoneyAPI client and call the operation_history method. ```python import asyncio from glQiwiApi import YooMoneyAPI TOKEN = 'your token' async def main(): async with YooMoneyAPI(api_access_token=TOKEN) as w: print(await w.operation_history(records=50)) asyncio.run(main()) ``` -------------------------------- ### Simultaneous Polling with Aiogram Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst Example of integrating QIWI API polling with aiogram to handle messages and provide responses. This allows for concurrent operation of both systems. ```python import logging from aiogram import Bot, Dispatcher, executor, types from glQiwiApi.core.event_fetching.executor import PollingExecutor API_TOKEN = "YOUR_API_TOKEN" bot = Bot(token=API_TOKEN) dp = Dispatcher(bot) @dp.message_handler() async def echo(message: types.Message): await message.answer("Hello!") if __name__ == "__main__": executor.start_polling(dp, skip_updates=True) # QIWI API polling qiwi_executor = PollingExecutor(client=client) @qiwi_executor.polling() def qiwi_handler(update: Update) -> None: print(update.data) if __name__ == "__main__": # You can run polling at on_startup event executor.start_polling(dp, skip_updates=True, on_startup=qiwi_executor.start_polling) ``` -------------------------------- ### Get QIWI Wallet Balance Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/index.rst Demonstrates how to retrieve the balance of a QIWI wallet using the glQiwiApi library. Ensure you have the correct API access token and phone number. Handles potential API errors. ```python import asyncio from glQiwiApi import QiwiWallet from glQiwiApi.qiwi.exceptions import QiwiAPIError async def print_balance(qiwi_token: str, phone_number: str) -> None: """ This function allows you to get balance of your wallet using glQiwiApi library """ async with QiwiWallet(api_access_token=qiwi_token, phone_number=phone_number) as w: try: balance = await w.get_balance() # handle exception if wrong credentials or really API return error except QiwiAPIError as err: print(err.json()) raise print(f"Your current balance is {balance.amount} {balance.currency.name}") asyncio.run(print_balance(qiwi_token="qiwi api token", phone_number="+phone_number")) ``` -------------------------------- ### Get YooMoney Access Token Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Retrieves an access token from YooMoney using a temporary code obtained from the authorization URL. This method should be called quickly after obtaining the code. ```python import asyncio from glQiwiApi import YooMoneyAPI async def get_token() -> None: print(await YooMoneyAPI.get_access_token( code='the code obtained from the link', client_id='Application ID received when registering the application above', redirect_uri='link provided during registration' )) asyncio.run(get_token()) ``` -------------------------------- ### Configuring Polling with Events Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst Demonstrates how to configure the start_polling function with specific events like on_startup and on_shutdown. The on_startup function is executed when polling begins. ```python from glQiwiApi.core.event_fetching.executor import PollingExecutor executor = PollingExecutor(client=client) @executor.polling() def handler(update: Update) -> None: print(update.data) @executor.on_startup() def on_startup_handler() -> None: print("Bot started polling!") @executor.on_shutdown() def on_shutdown_handler() -> None: print("Bot stopped polling!") ``` -------------------------------- ### Run Referrer Proxy with Docker Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Use Docker to pull and run the QIWI referrer proxy. This is useful for managing referrers and interacting with the QIWI API. ```bash docker pull ghcr.io/glef1x/glqiwiapi-proxy:latest docker run -p 80:80 ghcr.io/glef1x/glqiwiapi-proxy:latest ``` -------------------------------- ### Create a P2P Bill Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Asynchronously creates a P2P bill using the `QiwiP2PClient`. Requires a P2P secret token and the bill amount. Prints the bill ID and payment URL. ```python import asyncio from glQiwiApi import QiwiP2PClient async def create_p2p_bill(): async with QiwiP2PClient(secret_p2p="your p2p token") as p2p: bill = await p2p.create_p2p_bill(amount=1) print(f"Link to pay bill with {bill.id} id = {bill.pay_url}") asyncio.run(create_p2p_bill()) ``` -------------------------------- ### Configure QiwiWallet with SOCKS5 Proxy Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/advanced_features/proxy.rst This snippet shows how to create a RequestService that uses a SOCKS5 proxy. It requires the `aiohttp-socks` library. Ensure the proxy URL and port are correct. ```python import asyncio from aiohttp_socks import ProxyConnector from glQiwiApi import QiwiWallet from glQiwiApi.core import RequestService from glQiwiApi.core.session import AiohttpSessionHolder def create_request_service_with_proxy(w: QiwiWallet): return RequestService( session_holder=AiohttpSessionHolder( connector=ProxyConnector.from_url("socks5://34.134.60.185:443"), # some proxy headers={ "Content-Type": "application/json", "Accept": "application/json", "Authorization": f"Bearer {w._api_access_token}", "Host": "edge.qiwi.com", }, ) ) wallet = QiwiWallet( api_access_token="your token", phone_number="+phone number", request_service_factory=create_request_service_with_proxy, ) async def main(): async with wallet: print(await wallet.get_balance()) asyncio.run(main()) ``` -------------------------------- ### Create P2P Bill with Custom Shim URL Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Creates a P2P bill and generates a shim URL using a custom `shim_server_url` provided directly to the `QiwiP2PClient` constructor. This helps in avoiding QIWI wallet blocking. ```python import asyncio from glQiwiApi import QiwiP2PClient async def main(): async with QiwiP2PClient( secret_p2p="Your secret p2p api key", shim_server_url="https://some.url/your_proxy_path/" ) as client: bill = await client.create_p2p_bill(amount=1) shim_url = client.create_shim_url(bill.invoice_uid) asyncio.run(main()) ``` -------------------------------- ### Non-blocking Aiogram Polling with QIWI API Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/polling.rst Demonstrates running QIWI API polling within the aiogram's on_startup event for non-blocking execution. This approach integrates QIWI polling seamlessly into the aiogram application lifecycle. ```python import logging from aiogram import Bot, Dispatcher, executor, types from glQiwiApi.core.event_fetching.executor import PollingExecutor API_TOKEN = "YOUR_API_TOKEN" bot = Bot(token=API_TOKEN) dp = Dispatcher(bot) @dp.message_handler() async def echo(message: types.Message): await message.answer("Hello!") # QIWI API polling qiwi_executor = PollingExecutor(client=client) @qiwi_executor.polling() def qiwi_handler(update: Update) -> None: print(update.data) if __name__ == "__main__": # You can run polling at on_startup event executor.start_polling(dp, skip_updates=True, on_startup=qiwi_executor.start_polling) ``` -------------------------------- ### Create P2P Bill with Referrer Proxy Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Creates a P2P bill and generates a shim URL to potentially avoid QIWI wallet blocking issues when accessing P2P pages from certain services. Uses a provided `shim_server_url`. ```python import asyncio from glQiwiApi import QiwiP2PClient async def main(): async with QiwiP2PClient( secret_p2p="Your secret p2p api key", shim_server_url="http://referrerproxy-env.eba-cxcmwwm7.us-east-1.elasticbeanstalk.com/proxy/p2p/" ) as client: bill = await client.create_p2p_bill(amount=1) shim_url = client.create_shim_url(bill) asyncio.run(main()) ``` -------------------------------- ### Create and Check Bill without Middleware Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/usage_with_aiogram.rst This snippet shows how to create a P2P bill and check its payment status using glQiwiApi directly within aiogram message handlers, without employing middleware for client injection. ```python from aiogram import Bot, Dispatcher, types from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.dispatcher import FSMContext from aiogram.utils import executor from glQiwiApi import QiwiP2PClient from glQiwiApi.qiwi.clients.p2p.types import Bill qiwi_p2p_client = QiwiP2PClient(secret_p2p="YOUR_SECRET_P2P_TOKEN") BOT_TOKEN = "BOT_TOKEN" bot = Bot(token=BOT_TOKEN, parse_mode=types.ParseMode.HTML) storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) @dp.message_handler(text="I want to pay") async def handle_creation_of_payment(message: types.Message, state: FSMContext): async with qiwi_p2p_client: bill = await qiwi_p2p_client.create_p2p_bill(amount=1) await message.answer(text=f"Ok, here's your invoice:\n {bill.pay_url}") await state.set_state("payment") await state.update_data(bill=bill) @dp.message_handler(state="payment", text="I have paid this invoice") async def handle_successful_payment(message: types.Message, state: FSMContext): async with state.proxy() as data: bill: Bill = data.get("bill") if await qiwi_p2p_client.check_if_bill_was_paid(bill): await message.answer("You have successfully paid your invoice") await state.finish() else: await message.answer("Invoice was not paid") if __name__ == "__main__": executor.start_polling(dp, skip_updates=True) ``` -------------------------------- ### Handle QIWI API Exceptions Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Demonstrates how to gracefully handle potential QIWI API errors using a try-except block. Catches `QiwiAPIError` and allows access to the JSON response or plain text error message. ```python import asyncio from glQiwiApi import QiwiWallet from glQiwiApi.qiwi.exceptions import QiwiAPIError async def main(): async with QiwiWallet(api_access_token="", phone_number="+ ") as wallet: try: await wallet.transfer_money(to_phone_number="wrong number", amount=-1) except QiwiAPIError as ex: ex.json() # json response from API print(ex) # full traceback asyncio.run(main()) ``` -------------------------------- ### Check P2P Bill Status Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Creates a P2P bill and then checks if it has been paid using `check_if_bill_was_paid`. Requires a P2P secret token and the bill amount. ```python from glQiwiApi import QiwiP2PClient async def create_and_check_p2p_bill(): async with QiwiP2PClient(secret_p2p="your p2p token") as p2p: bill = await p2p.create_p2p_bill(amount=777) if await p2p.check_if_bill_was_paid(bill): # some logic ``` -------------------------------- ### Arbitrary Inputs Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/types/arbitrary/index.rst This section covers input types used for handling arbitrary data within the glQiwiApi library, as defined in the `glQiwiApi.types.arbitrary.inputs` module. ```APIDOC ## Arbitrary Inputs Module ### Description This module contains various input types designed for handling arbitrary data structures and parameters within the API interactions. These types facilitate flexible data passing for different operations. ### Members - `InputData`: A general-purpose input type for arbitrary data. - `SpecificInputType`: An example of a more specialized input type (details would be listed if available in source). ``` -------------------------------- ### Obtain URL for YooMoney Authorization Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Generates a URL to authorize your application with YooMoney. Use this URL to obtain a temporary code. Ensure correct scope, client_id, and redirect_uri are provided. ```python import asyncio from glQiwiApi import YooMoneyAPI async def get_url_to_auth() -> None: # Get a link for authorization, follow it if we get invalid_request or some kind of error # means either the scope parameter is incorrectly passed, you need to reduce the list of rights or try to recreate the application print(await YooMoneyAPI.build_url_for_auth( # For payments, account verification and payment history, you need to specify scope = ["account-info", "operation-history", "operation-details", "payment-p2p"] scope=["account-info", "operation-history"], client_id='ID received when registering the application above', redirect_uri='the link specified during registration above in the Redirect URI field' )) asyncio.run(get_url_to_auth()) ``` -------------------------------- ### Fetch YooMoney Account Information Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Retrieves account information, including status and balance, for a YooMoney account. The data is returned as an AccountInfo pydantic model. ```python import asyncio from glQiwiApi import YooMoneyAPI TOKEN = 'your_token' async def main(): w = YooMoneyAPI(TOKEN) async with w: # This gives you account information as AccountInfo pydantic model. get_account_info = await w.retrieve_account_info() print(get_account_info.account_status) print(get_account_info.balance) asyncio.run(main()) ``` -------------------------------- ### File Type Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/types/arbitrary/index.rst The `File` type is a custom type returned by methods such as `QiwiWallet.get_receipt`. It provides functionality to save the receipt or access its raw bytes. ```APIDOC ## File Type ### Description Represents a file, typically a receipt, that can be saved or accessed as raw bytes. This type is returned by methods like `QiwiWallet.get_receipt`. ### Methods - `save(path: str)`: Saves the file content to the specified path. - `get_raw()`: Returns the raw bytes of the file content. ``` -------------------------------- ### Retrieve Transaction History Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Asynchronously fetches and iterates through transaction history for a QIWI wallet. Requires QIWI API token and phone number. ```python import asyncio from glQiwiApi import QiwiWallet async def get_history(qiwi_token: str, phone_number: str) -> None: async with QiwiWallet(api_access_token=qiwi_token, phone_number=phone_number) as wallet: for transaction in await wallet.history(): # handle asyncio.run(get_history(qiwi_token="qiwi api token", phone_number="+phone number")) ``` -------------------------------- ### Create YooMoney Payment Form Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Generates a payment form link without making an API request. This is useful for creating donation or payment links with specified details. ```python from glQiwiApi import YooMoneyAPI TOKEN = 'your token' link = YooMoneyAPI.create_pay_form( receiver="4100116602400968", quick_pay_form="donate", targets="donation", payment_type="PC", amount=50 ) print(link) ``` -------------------------------- ### Transfer Money to a Card Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Asynchronously transfers a specified amount to a bank card. Requires QIWI API token, sender's phone number, card number, and amount. ```python import asyncio from glQiwiApi import QiwiWallet async def transfer_money_to_card(qiwi_token: str, phone_number: str) -> None: async with QiwiWallet(api_access_token=qiwi_token, phone_number=phone_number) as wallet: await wallet.transfer_money_to_card(card_number="desired card number", amount=50) asyncio.run(transfer_money_to_card(qiwi_token="token", phone_number="+phone number")) ``` -------------------------------- ### Fixing ClientConnectorError with Custom Session Holder Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/advanced_features/known-issues.rst This code demonstrates how to resolve a `aiohttp.client_exceptions.ClientConnectorError` by creating a custom `RequestService` with an `AiohttpSessionHolder`. This is useful when direct connections to the API fail, allowing for custom headers and host configurations. ```python import glQiwiApi from glQiwiApi import QiwiWallet from glQiwiApi.core import RequestService from glQiwiApi.core.session import AiohttpSessionHolder async def create_request_service(w: QiwiWallet): return RequestService( session_holder=AiohttpSessionHolder( headers={ "Content-Type": "application/json", "Accept": "application/json", "Authorization": f"Bearer {w._api_access_token}", "Host": "edge.qiwi.com", "User-Agent": f"glQiwiApi/{glQiwiApi.__version__}", }, trust_env=True ) ) wallet = QiwiWallet(request_service_factory=create_request_service) ``` -------------------------------- ### Cache Invalidation by Timer Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/advanced_features/cache.rst Illustrates using CacheInvalidationByTimerStrategy to automatically invalidate cache entries after a specified duration. This is useful for ensuring data freshness. ```python import asyncio from glQiwiApi.core.cache import InMemoryCacheStorage, CacheInvalidationByTimerStrategy storage = InMemoryCacheStorage(CacheInvalidationByTimerStrategy(cache_time_in_seconds=1)) async def main(): await storage.update(x=5) await asyncio.sleep(1) value = await storage.retrieve("x") # None asyncio.run(main()) ``` -------------------------------- ### Transfer Money to Another QIWI Wallet Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/qiwi/examples.rst Asynchronously transfers a specified amount to another QIWI wallet. Requires QIWI API token, sender's phone number, recipient's phone number, and amount. ```python import asyncio from glQiwiApi import QiwiWallet async def transfer_money_to_another_wallet(qiwi_token: str, phone_number: str) -> None: async with QiwiWallet(api_access_token=qiwi_token, phone_number=phone_number) as wallet: await wallet.transfer_money(to_phone_number="+754545343", amount=1) asyncio.run(transfer_money_to_another_wallet(qiwi_token="token", phone_number="+phone number")) ``` -------------------------------- ### Transfer Money and Check Transaction Source: https://github.com/glef1x/glqiwiapi/blob/dev-2.x/docs/getting-started/yoomoney/examples.rst Sends funds to another YooMoney account and then checks if the transaction was successful. This involves initiating a transfer and verifying its existence using the payment ID. ```python import asyncio from glQiwiApi import YooMoneyAPI TOKEN = 'your_token' async def main(): w = YooMoneyAPI(TOKEN) async with w: # So you can send funds to another account, in the example this is a transfer to account 4100116602400968 # worth 2 rubles with the comment "I LOVE glQiwiApi" payment = await w.transfer_money( to_account='4100116602400968', comment='I LOVE glQiwiApi', amount=2 ) # This way you can check the transaction, whether it was received by the person on the account print(await w.check_if_operation_exists( check_fn=lambda o: o.id == payment.payment_id )) asyncio.run(main()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.