### Quick Start Example Source: https://github.com/18studio/avito_python_api/blob/main/README.md Demonstrates basic usage of AvitoClient for fetching profile and ad information. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: profile = avito.account().get_self() ad = avito.ad(item_id=42, user_id=123).get() print(profile.name) print(ad.title) ``` -------------------------------- ### Configuration Commands Examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples of using the `avito config` commands. ```bash avito config set active-profile main avito config get active-profile avito config get active-profile --show-source avito config list --show-source avito config unset active-profile ``` -------------------------------- ### Account Commands Examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples of using the `avito account` commands. ```bash avito account add main --client-id client-id --user-id 123 printf '%s\n' 'client-secret' | avito --no-input account add main \ --client-id client-id \ --client-secret-stdin avito account use main avito account delete old --confirm old ``` -------------------------------- ### Helper Workflows Examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples of using auxiliary helper commands. ```bash avito account-health show --user-id 123 avito listing-health show --user-id 123 --limit 20 avito chat-summary show --user-id 123 avito order-summary show avito review-summary show avito promotion-summary show --item-ids 456 avito capabilities show ``` -------------------------------- ### Example Commands Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples demonstrating the usage of global flags and resource/action commands. ```bash avito --profile main account get-self ``` ```bash avito --json --no-input --profile main account get-balance --user-id 123 ``` -------------------------------- ### First API call examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Examples of making the first API calls using the CLI. ```bash avito --profile main account get-self avito --profile main account get-balance --user-id 123 ``` -------------------------------- ### Installation with Poetry Source: https://github.com/18studio/avito_python_api/blob/main/README.md Install the avito-py package using Poetry. ```bash poetry add avito-py ``` -------------------------------- ### Installation and verification Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Install the avito-py package and verify the CLI installation. ```bash pip install avito-py avito --version python -m avito --help ``` -------------------------------- ### API Commands Examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples of interacting with the Avito API using CLI commands. ```bash avito --profile main account get-self avito --profile main account get-balance --user-id 123 avito --profile main ad get --user-id 123 --item-id 456 ``` -------------------------------- ### Help Command Examples Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Examples of how to use the help command for the Avito CLI. ```bash avito --help avito account --help avito account get-self --help avito help account avito help account get-self ``` -------------------------------- ### CLI Examples Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples of using the Avito CLI for account management and data retrieval. ```bash avito account add main --client-id client-id --user-id 123 avito --profile main account get-self avito --json --no-input --profile main account get-balance --user-id 123 ``` -------------------------------- ### Promotion Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples of using the Avito Python API for promotion-related operations, including listing orders, getting forecasts, creating budgets, and retrieving campaign information. ```python from avito import AvitoClient from datetime import datetime with AvitoClient.from_env() as avito: services = avito.promotion_order().list_orders() forecast = avito.bbip_promotion(item_id=42).get_forecasts(items=[]) budget = avito.autostrategy_campaign().create_budget( campaign_type="AS", start_time=datetime(2026, 4, 20), finish_time=datetime(2026, 4, 27), items=[42, 43], ) campaign = avito.autostrategy_campaign(campaign_id=15).get() campaigns = avito.autostrategy_campaign().list( limit=50, status_id=[1, 2], order_by=[("startTime", "asc")], updated_from=datetime(2026, 4, 1), updated_to=datetime(2026, 4, 30), ) print(budget.calc_id) print(campaign.campaign.title if campaign.campaign else None) print(campaigns.total_count) ``` -------------------------------- ### Command Examples Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Illustrative examples of Avito CLI commands. ```bash avito account get-self ``` ```bash avito account get-balance --user-id 123 ``` ```bash avito ad get --item-id 456 --user-id 123 ``` ```bash avito ad-stats get-item-stats --user-id 123 --item-ids 456,789 --date-from 2026-05-01 ``` ```bash avito promotion-order list-services --item-id 456 --json ``` -------------------------------- ### Debug Information Source: https://github.com/18studio/avito_python_api/blob/main/README.md Example of how to get debug information from the AvitoClient. ```python from avito import AvitoClient client = AvitoClient.from_env() info = client.debug_info() print(info.base_url) print(info.user_id) print(info.retry_max_attempts) client.close() ``` -------------------------------- ### Status and Doctor Commands Examples Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md Examples for checking the CLI status and running diagnostics. ```bash avito status avito --json status avito doctor ``` -------------------------------- ### Orders and Delivery Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples for managing orders and delivery using the Avito Python API, including listing orders, creating labels, and getting stock information. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: orders = avito.order().list() label_task = avito.order_label().create(order_ids=["100500"]) label_pdf = avito.order_label(task_id=label_task.task_id).download() stock_info = avito.stock().get(item_ids=[100500]) ``` -------------------------------- ### Jobs Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples for interacting with job postings and applications via the Avito Python API, including listing vacancies, getting application IDs, and retrieving resumes. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: vacancies = avito.vacancy().list(query="python") application_ids = avito.application().get_ids(updated_at_from="2026-04-18") applications = avito.application().get_by_ids(ids=[application_ids.items[0].id]) resumes = avito.resume().list(query="оператор") webhooks = avito.job_webhook().list() ``` -------------------------------- ### Discover Swagger Bindings Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Example of building a CLI registry from existing SDK metadata. ```python discover_swagger_bindings(registry=load_swagger_registry(...)) ``` -------------------------------- ### Pagination Example Source: https://github.com/18studio/avito_python_api/blob/main/README.md Demonstrates how to use pagination with the Avito Python API, showing how to retrieve items, access specific elements, and materialize the entire list. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: items = avito.ad(user_id=123).list(status="active", limit=50, page_size=25) first = items[0] preview = items[:10] all_items = items.materialize() ``` -------------------------------- ### Async Client Usage Source: https://github.com/18studio/avito_python_api/blob/main/README.md Example of using AsyncAvitoClient for asynchronous operations. ```python from avito import AsyncAvitoClient async with AsyncAvitoClient.from_env() as avito: profile = await avito.account().get_self() listings = await (await avito.ad(user_id=123).list(limit=20)).materialize() ``` -------------------------------- ### Auxiliary workflows Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Examples of public helper commands that call public AvitoClient methods. ```bash avito --profile main account-health show --user-id 123 avito --profile main listing-health show --user-id 123 --limit 20 avito --profile main chat-summary show --user-id 123 avito --profile main order-summary show avito --profile main review-summary show avito --profile main promotion-summary show --item-ids 456 avito capabilities show ``` -------------------------------- ### Canonical Invocation Syntax for Global Options Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Examples of how to use global options with commands. ```bash avito --profile main account get-self ``` ```bash avito --json --no-input account get-self ``` -------------------------------- ### Help commands Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Get help for commands using the 'help' subcommand. ```bash avito help account avito help account get-balance ``` -------------------------------- ### Real Estate, Reviews, and Tariffs Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples for managing real estate listings, reviews, and tariffs using the Avito Python API, including booking updates and price adjustments. ```python from avito import AvitoClient from avito.realty import RealtyPricePeriod with AvitoClient.from_env() as avito: booking = avito.realty_booking(20, user_id=10) booking.update_bookings_info(blocked_dates=["2026-05-01"]) bookings = booking.list_realty_bookings(date_start="2026-05-01", date_end="2026-05-05") avito.realty_pricing(20, user_id=10).update_realty_prices( periods=[RealtyPricePeriod(date_from="2026-05-01", price=5000)] ) reviews = avito.review().list() tariff = avito.tariff().get_tariff_info() ``` -------------------------------- ### TTFC Measurement Procedure Source: https://github.com/18studio/avito_python_api/blob/main/CONTRIBUTING.md Steps to measure Time To First Call (TTFC) for new users, which involves setting up a clean environment, installing the package, configuring credentials, and running the getting started tutorial. ```bash pip install avito-py ``` -------------------------------- ### JSON Error Format Example Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md An example of how errors are formatted in JSON. ```json { "code": "INVALID_FLAG_COMBINATION", "exit_code": 2, "message": "Флаги --json, --plain, --table и --wide нельзя использовать вместе." } ``` -------------------------------- ### Client Initialization: From Environment Variables Source: https://github.com/18studio/avito_python_api/blob/main/README.md Initialize AvitoClient using environment variables. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: ... ``` -------------------------------- ### Client Initialization: Full Configuration with AvitoSettings Source: https://github.com/18studio/avito_python_api/blob/main/README.md Initialize AvitoClient with a full AvitoSettings object. ```python from avito import AuthSettings, AvitoClient, AvitoSettings settings = AvitoSettings( base_url="https://api.avito.ru", user_id=123, auth=AuthSettings( client_id="client-id", client_secret="client-secret", ), ) with AvitoClient(settings) as avito: ... ``` -------------------------------- ### Human Error Format Example Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/reference/cli.md An example of how errors are formatted for human readability. ```text INVALID_FLAG_COMBINATION: Флаги --json, --plain, --table и --wide нельзя использовать вместе. ``` -------------------------------- ### Create client from environment variables Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/auth-and-config.md Creating an AvitoClient instance using environment variables. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: profile = avito.account().get_self() print(profile.user_id) ``` -------------------------------- ### Create client with AvitoSettings Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/auth-and-config.md Creating an AvitoClient instance using AvitoSettings and AuthSettings for full control. ```python from avito import AuthSettings, AvitoClient, AvitoSettings settings = AvitoSettings( user_id=123, auth=AuthSettings( client_id="client-id", client_secret="client-secret", ), ) with AvitoClient(settings) as avito: info = avito.debug_info() print(info.user_id) ``` -------------------------------- ### Enum and Model Example Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/domain-architecture-v2.md Example of an enum and a dataclass model within a domain. ```python from dataclasses import dataclass from enum import StrEnum from avito.core.models import ApiModel from avito.core.payload import JsonReader class OrderStatus(StrEnum): CREATED = "created" PAID = "paid" DELIVERED = "delivered" CANCELLED = "cancelled" UNKNOWN = "unknown" @dataclass(slots=True, frozen=True) class OrderInfo(ApiModel): order_id: str status: OrderStatus @classmethod def from_payload(cls, payload: object) -> "OrderInfo": reader = JsonReader(payload) return cls( order_id=reader.required_str("id", "order_id", "orderId"), status=reader.enum(OrderStatus, "status", unknown=OrderStatus.UNKNOWN), ) ``` -------------------------------- ### Release Tagging and Pushing Source: https://github.com/18studio/avito_python_api/blob/main/README.md Commands for tagging and pushing a release. ```bash git tag v1.0.2 git push origin v1.0.2 ``` -------------------------------- ### Public Domain Method Example Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/domain-architecture-v2.md Example of a public domain method that remains explicit with signature, docstring, and Swagger binding visible in the code and documentation. ```python from dataclasses import dataclass from typing import cast from avito.core.domain import DomainObject from avito.core.swagger import swagger_operation from avito.ratings import operations from avito.ratings.models import CreateReviewAnswerRequest, ReviewAnswerInfo @dataclass(slots=True, frozen=True) class ReviewAnswer(DomainObject): __swagger_domain__ = "ratings" __sdk_factory__ = "review_answer" __sdk_factory_args__ = {"answer_id": "path.answer_id"} answer_id: int | str | None = None @swagger_operation( "POST", "/ratings/v1/answers", spec="Рейтингииотзывы.json", operation_id="createReviewAnswerV1", method_args={"review_id": "body.review_id", "text": "body.message"}, ) def create( self, *, review_id: int, text: str, idempotency_key: str | None = None, ) -> ReviewAnswerInfo: """Создаёт ответ на отзыв. Параметр `idempotency_key` задаёт ключ идемпотентности для безопасного повтора write-операции. Raises: AvitoError с полями operation, status, request_id, attempt, method и endpoint. """ request = CreateReviewAnswerRequest(review_id=review_id, text=text) return cast(ReviewAnswerInfo, self._execute( operations.CREATE_REVIEW_ANSWER, request=request, idempotency_key=idempotency_key, )) ``` -------------------------------- ### Operation Description Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/domain-architecture-v2.md Example of an HTTP contract operation description. ```python from avito.core.operations import OperationSpec from avito.ratings.models import CreateReviewAnswerRequest, ReviewAnswerInfo CREATE_REVIEW_ANSWER = OperationSpec( name="ratings.answers.create", method="POST", path="/ratings/v1/answers", request_model=CreateReviewAnswerRequest, response_model=ReviewAnswerInfo, retry_mode="enabled", ) ``` -------------------------------- ### Хранение секретов в переменных окружения Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/security-practices.md SDK читает AVITO_CLIENT_ID и AVITO_CLIENT_SECRET автоматически. Файл .env добавьте в .gitignore. ```bash AVITO_CLIENT_ID=your_client_id AVITO_CLIENT_SECRET=your_client_secret ``` -------------------------------- ### Run Core and Contract Tests Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Command to run core swagger linter and swagger contracts tests. ```bash poetry run pytest tests/core/test_swagger_linter.py tests/contracts/test_swagger_contracts.py ``` -------------------------------- ### Request Model with Metadata Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/domain-architecture-v2.md Example of a Request-model using metadata for API field names. ```python from dataclasses import dataclass from avito.core.fields import api_field from avito.core.models import RequestModel @dataclass(slots=True, frozen=True) class CreateReviewAnswerRequest(RequestModel): review_id: int = api_field("reviewId") text: str = api_field("text") ``` -------------------------------- ### Client Initialization: Direct Client ID/Secret Source: https://github.com/18studio/avito_python_api/blob/main/README.md Initialize AvitoClient directly with client_id and client_secret. ```python from avito import AvitoClient with AvitoClient(client_id="client-id", client_secret="client-secret") as avito: ... ``` -------------------------------- ### Save active profile in local configuration Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Commands to set and get the active profile from the local configuration. ```bash avito config set active-profile main avito config get active-profile --show-source avito config list --show-source ``` -------------------------------- ### Manage profiles Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/how-to/cli.md Commands to list, use, and delete profiles. ```bash avito account list avito account use main avito account current avito account delete old-profile --confirm old-profile ``` -------------------------------- ### Swagger Bindings by HTTP Method Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Command to count Swagger bindings by HTTP method (read/write) using factory metadata. ```bash poetry run python -c "from collections import Counter; from avito.core.swagger_discovery import discover_swagger_bindings; from avito.core.swagger_registry import load_swagger_registry; reg=load_swagger_registry(); ops={op.key: op for op in reg.operations}; d=discover_swagger_bindings(registry=reg); c=Counter(); [c.update([ops[b.operation_key].method, 'read' if ops[b.operation_key].method in {'GET','HEAD'} else 'write']) for b in d.bindings if b.variant == 'sync' and b.operation_key is not None]; print(c)" ``` -------------------------------- ### Verification Commands Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands to verify the implementation of registry help, aliases, and collision detection. ```bash poetry run pytest tests/cli/test_registry.py tests/cli/test_app.py poetry run python scripts/lint_python_guidelines.py poetry run python scripts/lint_architecture.py poetry run mypy avito poetry run ruff check avito/cli tests/cli ``` -------------------------------- ### Minimal Async Domain Template Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/async-domain-template.md A basic example of an async domain template, demonstrating the structure and key components. ```python from dataclasses import dataclass from avito.core import ApiTimeouts, RetryOverride from avito.core.domain import AsyncDomainObject from avito.core.swagger import swagger_operation from avito..models import ResultModel from avito..operations import GET_RESULT @dataclass(slots=True, frozen=True) class AsyncExample(AsyncDomainObject): __swagger_domain__ = "example" __sdk_factory__ = "example" __sdk_factory_args__ = {"item_id": "path.item_id"} item_id: int | str | None = None @swagger_operation( "GET", "/example/{item_id}", spec="Example.json", operation_id="getExample", variant="async", ) async def get( self, *, timeout: ApiTimeouts | None = None, retry: RetryOverride | None = None ) -> ResultModel: return await self._execute( GET_RESULT, path_params={"item_id": self.item_id}, timeout=timeout, retry=retry, ) ``` -------------------------------- ### Poetry Scripts Configuration Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Defines the entry point for the CLI tool 'avito' using Poetry's script configuration. ```toml [tool.poetry.scripts]\navito = "avito.cli.app:main" ``` -------------------------------- ### JSON Report Structure Source: https://github.com/18studio/avito_python_api/blob/main/docs/site/explanations/swagger-binding-subsystem.md Example structure of a JSON report generated by the linter, showing summary statistics and detailed operation/binding information. ```json { "summary": { "specs": 23, "operations_total": 204, "deprecated_operations": 7, "bound": 204, "unbound": 0, "duplicate": 0, "ambiguous": 0 }, "operations": [], "bindings": [], "factory_mapping": {}, "errors": [] } ``` -------------------------------- ### Verification Commands Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands to verify the implementation of the registry and related linting/typing checks. ```bash poetry run pytest tests/cli/test_registry.py poetry run python scripts/lint_python_guidelines.py poetry run python scripts/lint_architecture.py poetry run mypy avito poetry run ruff check avito/cli tests/cli ``` -------------------------------- ### Verification Commands Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands used to verify the repository state and linter contracts. ```bash poetry run python -c "from avito.core.swagger_discovery import discover_swagger_bindings; print(len(discover_swagger_bindings().canonical_map))" poetry run python -c "from avito.core.swagger_discovery import discover_swagger_bindings; d=discover_swagger_bindings(); print(len([b for b in d.bindings if b.variant == 'sync' and b.operation_key is not None and b.factory is None]))" poetry run python -m avito poetry run pytest tests/core/test_swagger_linter.py tests/contracts/test_swagger_contracts.py ``` -------------------------------- ### Autoteka Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples for utilizing the Autoteka service via the Avito Python API, including resolving catalog information, creating VIN previews, and generating reports. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: catalog = avito.autoteka_vehicle().resolve_catalog(brand_id=1) preview = avito.autoteka_vehicle().create_preview_by_vin(vin="XTA00000000000000") report = avito.autoteka_report().create_report(preview_id=int(preview.preview_id or 0)) reports = avito.autoteka_report().list_reports() ``` -------------------------------- ### Quality Checks Source: https://github.com/18studio/avito_python_api/blob/main/README.md Commands for running quality checks. ```bash make check ``` ```bash make fmt make lint make typecheck make test make quality make build ``` -------------------------------- ### Verification Commands for Stage 7 Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands to verify the implementation of result serialization and pagination. ```bash poetry run pytest tests/cli/test_serialization.py poetry run python scripts/lint_python_guidelines.py poetry run python scripts/lint_architecture.py poetry run mypy avito poetry run ruff check avito/cli tests/cli ``` -------------------------------- ### Documentation Checks Source: https://github.com/18studio/avito_python_api/blob/main/CONTRIBUTING.md Commands to run documentation checks before submitting a PR that modifies the public API, README, or docs/site/. Includes installing lychee for link checking. ```bash make docs-strict make docs-report ``` ```bash brew install lychee ``` ```bash cargo binstall lychee ``` ```bash make docs-check ``` -------------------------------- ### CPA and CallTracking Source: https://github.com/18studio/avito_python_api/blob/main/README.md Examples for using CPA (Cost Per Action) and CallTracking features with the Avito Python API, including listing calls and retrieving call tracking data. ```python from avito import AvitoClient with AvitoClient.from_env() as avito: calls = avito.cpa_call().list( date_time_from="2026-04-18T00:00:00Z", limit=100, ) calltracking = avito.call_tracking_call(10).get() records = avito.call_tracking_call(10).download() ``` -------------------------------- ### Verification Commands Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands to verify the implementation of the command adapter extension point. ```bash poetry run pytest tests/cli/test_adapters.py tests/cli/test_commands.py poetry run python scripts/lint_cli_coverage.py --phase registry poetry run python scripts/lint_python_guidelines.py poetry run python scripts/lint_architecture.py poetry run mypy avito poetry run mypy scripts/lint_cli_coverage.py poetry run ruff check avito/cli tests/cli ``` -------------------------------- ### Full gate commands Source: https://github.com/18studio/avito_python_api/blob/main/todo.md Commands to run the full gate before completing the branch. ```bash poetry run pytest tests/cli poetry run pytest tests/core/test_swagger*.py tests/contracts/test_swagger_contracts.py poetry run mypy avito poetry run mypy scripts/lint_cli_coverage.py poetry run ruff check . poetry run python scripts/lint_python_guidelines.py poetry run python scripts/lint_architecture.py poetry run python scripts/lint_cli_coverage.py --strict poetry build make check ```