Skip to main content

Unofficial Yandex Search API client for Python

Project description

Yandex Search API Client

A Python client for interacting with Yandex's Search API, providing easy access to Yandex search results programmatically.

Features

  • Perform searches using Yandex's Search API
  • Retrieve search results in XML format
  • Extract URLs from search results
  • Automatic IAM token management
  • Configurable search parameters (region, search type, number of results)
  • Asynchronous operation with timeout handling

Installation

pip install yandex-search-api

Usage

Basic Example

import logging
from yandex_search_api import YandexSearchAPIClient
from yandex_search_api.client import SearchType


def main():
    # Initialize client with your credentials
    client = YandexSearchAPIClient(
        folder_id="your_folder_id",
        oauth_token="your_oauth_token"
    )
    # How to get folder_id: https://yandex.cloud/en-ru/docs/resource-manager/operations/folder/get-id
    # How to get  oauth_token:  https://yandex.cloud/en-ru/docs/iam/concepts/authorization/oauth-token

    links = client.get_links(
        query_text="Python library for yandex search",
        search_type=SearchType.RUSSIAN,
        n_links=5
    )
    
    print("Search results:", links)

if __name__ == '__main__':
    main()

Advanced Usage

# Perform a search and get raw XML results
operation_id = client.search(
    query_text="Advanced search example",
    search_type=SearchType.INTERNATIONAL,
    region=Region.UKRAINE,
    n_links=20
)

# Wait for results and get XML
xml_results = client.get_search_results(operation_id)

# Or use the convenience method that waits automatically
xml_results = client.search_and_wait(
    query_text="Another example",
    max_wait=120,  # seconds
    interval=5     # seconds between checks
)

Configuration

Required Credentials

  1. Folder ID: Your Yandex Cloud folder ID https://yandex.cloud/en-ru/docs/resource-manager/operations/folder/get-id
  2. OAuth Token: Your Yandex OAuth token https://yandex.cloud/en-ru/docs/iam/concepts/authorization/oauth-token

Search Parameters

  • search_type:

    • SearchType.RUSSIAN (default)
    • SearchType.TURKISH
    • SearchType.INTERNATIONAL
  • region:

    • Region.RUSSIA (default)
    • Region.UKRAINE
    • Region.BELARUS
    • Region.KAZAKHSTAN
  • n_links: Number of results to return (default: 10)

  • page: Page number (default: 0)

  • max_wait: Maximum time to wait for results in seconds (default: 300)

  • interval: Time between operation status checks in seconds (default: 1)

Logging

The library uses Python's logging module with logger name YandexSearchApi. Configure logging as needed:

import logging
logging.getLogger('YandexSearchApi').setLevel(logging.DEBUG)

License

MIT License

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

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

yandex_search_api-0.1.3.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

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

yandex_search_api-0.1.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file yandex_search_api-0.1.3.tar.gz.

File metadata

  • Download URL: yandex_search_api-0.1.3.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for yandex_search_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2f48849d5240058bd4010e6aab22b333e1c1799a4d16fb5eceaef37761feaafa
MD5 05d6080cd0a3d6c4db134f5ae7fa52cb
BLAKE2b-256 d7afcb5f0ac1be203ed3a5191232116ee1d1b3d83f17783d8278e84f2f4ef68e

See more details on using hashes here.

File details

Details for the file yandex_search_api-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for yandex_search_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71a7efab663a2ed0c50b801129de71f67ae9b9015a33183a38a95625db0b0bae
MD5 9793dca714354b0bf6d8afe8f4ef43d7
BLAKE2b-256 69730415e08abe0216956a8ab4e5d194e639fdff441e4d4af8b1b88b90c84d08

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