ya-business-api


Nameya-business-api JSON
Version 0.1.0rc1 PyPI version JSON
download
home_pageNone
SummaryYandex business API client
upload_time2024-05-08 13:26:32
maintainerNone
docs_urlNone
authorKirill_Lekhov
requires_python<4.0.0,>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Yandex business (sprav) API client [![codecov](https://codecov.io/gh/Kirill-Lekhov/ya-business-api/graph/badge.svg?token=9Q77PG68W1)](https://codecov.io/gh/Kirill-Lekhov/ya-business-api)

## Installation
```sh
# Sync only mode
pip install ya_business_api[sync]
# Async only mode
pip install ya_business_api[async]
# All modes
pip install ya_business_api[all]
```

## Instantiating
There are several ways to work with the API (synchronous and asynchronous).
Both interfaces have the same signatures, the only difference is the need to use async/await keywords.

```python
from ya_business_api.sync_api import SyncAPI		# Sync mode
from ya_business_api.async_api import AsyncAPI		# Async mode


def main() -> None:
	api = SyncAPI.build(
		csrf_token=...,
		session_id=...,
		session_id2=...,
	)

	# Do things here...


async def main() -> None:
	api = await AsyncAPI.build(
		csrf_token=...,
		session_id=...,
		session_id2=...,
	)

	# Do things here...

	await api.session.close()
```

### Where can I get the data for the client?
On the reviews page (https://yandex.ru/sprav/.../edit/reviews), open the developer console (usually `F12`) from the first request, copy values of cookies (`Session_id` and `sessionid2`).

In the console, run the following script:
```JS
function getData() {
	console.info({
		"CSRFToken": window?.__PRELOAD_DATA?.initialState?.env?.csrf,
		"PermanentId": window?.__PRELOAD_DATA?.initialState?.edit?.company?.permanent_id,
	})
}

getData()

/**
 * {CSRFToken: "...", PermanentId: 00000000000}
*/
```

### ⚠️WARNING⚠️
The `CSRFToken` and `PermanentId` belong to certain companies and cannot be used to respond to reviews from another company.

## Reviews
### Reviews fetching
```python
# Sync mode
from ya_business_api.sync_api import SyncAPI
from ya_business_api.reviews.dataclasses.requests import ReviewsRequest


api = SyncAPI.build(**kwargs)
request = ReviewsRequest(permanent_id=<permanent_id>)
response = api.reviews.get_reviews(request)

# Async mode
from ya_business_api.async_api import AsyncAPI
from ya_business_api.reviews.dataclasses.requests import ReviewsRequest


api = await AsyncAPI.build(**kwargs)
request = ReviewsRequest(permanent_id=<permanent_id>)
response = await api.reviews.get_reviews(request)
await api.session.close()
```

#### Filtering and ordering
```python
from ya_business_api.sync_api import SyncAPI
from ya_business_api.reviews.dataclasses.requests import ReviewsRequest
from ya_business_api.reviews.constants import Ranking


api = SyncAPI.build(**kwargs)
request = ReviewsRequest(
	permanent_id=<permanent_id>,
	ranking=Ranking.BY_RATING_DESC,
	unread=True,
	page=5,
)
response = api.reviews.get_reviews(request)
```

### Answering to reviews
```python
# Sync mode
from ya_business_api.sync_api import SyncAPI
from ya_business_api.reviews.dataclasses.requests import AnswerRequest


api = SyncAPI.build(**kwargs)
reviews = api.reviews.get_reviews()
request = AnswerRequest(
	review_id=reviews.list.items[0].id,
	text="Thank you!",
	reviews_csrf_token=reviews.list.csrf_token,
	answer_csrf_token=reviews.list.items[0].business_answer_csrf_token,
)
response = api.reviews.send_answer(request)

# Async mode
from ya_business_api.async_api import AsyncAPI
from ya_business_api.reviews.dataclasses.requests import AnswerRequest


api = await AsyncAPI.build(**kwargs)
reviews = await api.reviews.get_reviews()
request = AnswerRequest(
	review_id=reviews.list.items[0].id,
	text="Thank you!",
	reviews_csrf_token=reviews.list.csrf_token,
	answer_csrf_token=reviews.list.items[0].business_answer_csrf_token,
)
response = await api.reviews.send_answer(request)
await api.session.close()
```

## Companies
### Receiving companies
```python
# Sync mode
from ya_business_api.sync_api import SyncAPI


api = SyncAPI.build(**kwargs)
response = api.companies.get_companies()

# Async mode
from ya_business_api.async_mode


api = await AsyncAPI.build(**kwargs)
response = await api.companies.get_companies()

await api.session.close()
```

#### Filtering and pagination
```python
from ya_business_api.sync_api import SyncAPI
from ya_business_api.companies.dataclasses.requests import CompaniesRequest


api = SyncAPI.build(**kwargs)
request = CompaniesRequest(filter="My Company", page=5)
response = api.companies.get_companies(request)
```

## Shortcuts
### Answers deleting
```python
api.reviews.send_answer(AnswerRequest(text="", **kwargs))
```

### Automatic closing of the session (async mode)
```python
async with await AsyncAPI.make_session(session_id=..., session_id2=...) as session:
	api = AsyncAPI(permanent_id=..., csrf_token=..., session=session)
	...
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ya-business-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Kirill_Lekhov",
    "author_email": "kirill.lekhov@mail.ru",
    "download_url": "https://files.pythonhosted.org/packages/e1/c4/7cfbaacff76318b1d72f266cf9c7467794f8e40b72d82d79af19197992fa/ya_business_api-0.1.0rc1.tar.gz",
    "platform": null,
    "description": "# Yandex business (sprav) API client [![codecov](https://codecov.io/gh/Kirill-Lekhov/ya-business-api/graph/badge.svg?token=9Q77PG68W1)](https://codecov.io/gh/Kirill-Lekhov/ya-business-api)\n\n## Installation\n```sh\n# Sync only mode\npip install ya_business_api[sync]\n# Async only mode\npip install ya_business_api[async]\n# All modes\npip install ya_business_api[all]\n```\n\n## Instantiating\nThere are several ways to work with the API (synchronous and asynchronous).\nBoth interfaces have the same signatures, the only difference is the need to use async/await keywords.\n\n```python\nfrom ya_business_api.sync_api import SyncAPI\t\t# Sync mode\nfrom ya_business_api.async_api import AsyncAPI\t\t# Async mode\n\n\ndef main() -> None:\n\tapi = SyncAPI.build(\n\t\tcsrf_token=...,\n\t\tsession_id=...,\n\t\tsession_id2=...,\n\t)\n\n\t# Do things here...\n\n\nasync def main() -> None:\n\tapi = await AsyncAPI.build(\n\t\tcsrf_token=...,\n\t\tsession_id=...,\n\t\tsession_id2=...,\n\t)\n\n\t# Do things here...\n\n\tawait api.session.close()\n```\n\n### Where can I get the data for the client?\nOn the reviews page (https://yandex.ru/sprav/.../edit/reviews), open the developer console (usually `F12`) from the first request, copy values of cookies (`Session_id` and `sessionid2`).\n\nIn the console, run the following script:\n```JS\nfunction getData() {\n\tconsole.info({\n\t\t\"CSRFToken\": window?.__PRELOAD_DATA?.initialState?.env?.csrf,\n\t\t\"PermanentId\": window?.__PRELOAD_DATA?.initialState?.edit?.company?.permanent_id,\n\t})\n}\n\ngetData()\n\n/**\n * {CSRFToken: \"...\", PermanentId: 00000000000}\n*/\n```\n\n### \u26a0\ufe0fWARNING\u26a0\ufe0f\nThe `CSRFToken` and `PermanentId` belong to certain companies and cannot be used to respond to reviews from another company.\n\n## Reviews\n### Reviews fetching\n```python\n# Sync mode\nfrom ya_business_api.sync_api import SyncAPI\nfrom ya_business_api.reviews.dataclasses.requests import ReviewsRequest\n\n\napi = SyncAPI.build(**kwargs)\nrequest = ReviewsRequest(permanent_id=<permanent_id>)\nresponse = api.reviews.get_reviews(request)\n\n# Async mode\nfrom ya_business_api.async_api import AsyncAPI\nfrom ya_business_api.reviews.dataclasses.requests import ReviewsRequest\n\n\napi = await AsyncAPI.build(**kwargs)\nrequest = ReviewsRequest(permanent_id=<permanent_id>)\nresponse = await api.reviews.get_reviews(request)\nawait api.session.close()\n```\n\n#### Filtering and ordering\n```python\nfrom ya_business_api.sync_api import SyncAPI\nfrom ya_business_api.reviews.dataclasses.requests import ReviewsRequest\nfrom ya_business_api.reviews.constants import Ranking\n\n\napi = SyncAPI.build(**kwargs)\nrequest = ReviewsRequest(\n\tpermanent_id=<permanent_id>,\n\tranking=Ranking.BY_RATING_DESC,\n\tunread=True,\n\tpage=5,\n)\nresponse = api.reviews.get_reviews(request)\n```\n\n### Answering to reviews\n```python\n# Sync mode\nfrom ya_business_api.sync_api import SyncAPI\nfrom ya_business_api.reviews.dataclasses.requests import AnswerRequest\n\n\napi = SyncAPI.build(**kwargs)\nreviews = api.reviews.get_reviews()\nrequest = AnswerRequest(\n\treview_id=reviews.list.items[0].id,\n\ttext=\"Thank you!\",\n\treviews_csrf_token=reviews.list.csrf_token,\n\tanswer_csrf_token=reviews.list.items[0].business_answer_csrf_token,\n)\nresponse = api.reviews.send_answer(request)\n\n# Async mode\nfrom ya_business_api.async_api import AsyncAPI\nfrom ya_business_api.reviews.dataclasses.requests import AnswerRequest\n\n\napi = await AsyncAPI.build(**kwargs)\nreviews = await api.reviews.get_reviews()\nrequest = AnswerRequest(\n\treview_id=reviews.list.items[0].id,\n\ttext=\"Thank you!\",\n\treviews_csrf_token=reviews.list.csrf_token,\n\tanswer_csrf_token=reviews.list.items[0].business_answer_csrf_token,\n)\nresponse = await api.reviews.send_answer(request)\nawait api.session.close()\n```\n\n## Companies\n### Receiving companies\n```python\n# Sync mode\nfrom ya_business_api.sync_api import SyncAPI\n\n\napi = SyncAPI.build(**kwargs)\nresponse = api.companies.get_companies()\n\n# Async mode\nfrom ya_business_api.async_mode\n\n\napi = await AsyncAPI.build(**kwargs)\nresponse = await api.companies.get_companies()\n\nawait api.session.close()\n```\n\n#### Filtering and pagination\n```python\nfrom ya_business_api.sync_api import SyncAPI\nfrom ya_business_api.companies.dataclasses.requests import CompaniesRequest\n\n\napi = SyncAPI.build(**kwargs)\nrequest = CompaniesRequest(filter=\"My Company\", page=5)\nresponse = api.companies.get_companies(request)\n```\n\n## Shortcuts\n### Answers deleting\n```python\napi.reviews.send_answer(AnswerRequest(text=\"\", **kwargs))\n```\n\n### Automatic closing of the session (async mode)\n```python\nasync with await AsyncAPI.make_session(session_id=..., session_id2=...) as session:\n\tapi = AsyncAPI(permanent_id=..., csrf_token=..., session=session)\n\t...\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Yandex business API client",
    "version": "0.1.0rc1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4f93bb01b100416beb3ff10c501088d9609a24a922b699fa0d90a5dca888ce7",
                "md5": "c5b86503ee025941c1f8371055659c66",
                "sha256": "3f5175442e3139cd22cb97b671b034160793c3aa59801e2b6bdfff728345e55d"
            },
            "downloads": -1,
            "filename": "ya_business_api-0.1.0rc1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c5b86503ee025941c1f8371055659c66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 18152,
            "upload_time": "2024-05-08T13:26:31",
            "upload_time_iso_8601": "2024-05-08T13:26:31.025416Z",
            "url": "https://files.pythonhosted.org/packages/c4/f9/3bb01b100416beb3ff10c501088d9609a24a922b699fa0d90a5dca888ce7/ya_business_api-0.1.0rc1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e1c47cfbaacff76318b1d72f266cf9c7467794f8e40b72d82d79af19197992fa",
                "md5": "626e97ae43da6cfede31cdc00ede9797",
                "sha256": "0c787571c69fec6019473d65617412a0bebbeb4dd6cf0d2253abeab9a727a7a8"
            },
            "downloads": -1,
            "filename": "ya_business_api-0.1.0rc1.tar.gz",
            "has_sig": false,
            "md5_digest": "626e97ae43da6cfede31cdc00ede9797",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 11527,
            "upload_time": "2024-05-08T13:26:32",
            "upload_time_iso_8601": "2024-05-08T13:26:32.676055Z",
            "url": "https://files.pythonhosted.org/packages/e1/c4/7cfbaacff76318b1d72f266cf9c7467794f8e40b72d82d79af19197992fa/ya_business_api-0.1.0rc1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-08 13:26:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ya-business-api"
}
        
Elapsed time: 0.22234s