Simple Python SDK for AmoCRM API
Project description
amocrm-sdk
Python SDK for the AmoCRM REST API.
Installation
uv add amocrm-sdk
# or
pip install amocrm-sdk
Quick Start
OAuth2 setup
from amocrm import AmoCRM, OAuthConfig
from amocrm.auth import DjangoTokenStorage
oauth = OAuthConfig(
client_id="...",
client_secret="...",
redirect_uri="https://yourapp.com/oauth/callback",
storage=DjangoTokenStorage(AmoCRMToken.objects.get(id=1)),
)
# Первый запуск — обменять код авторизации на токены
client = AmoCRM.from_code(subdomain="your-company", code=auth_code, oauth=oauth)
# Последующие запуски — токены загружаются из storage автоматически
client = AmoCRM(subdomain="your-company", oauth=oauth)
Глобальный менеджер (Django / Flask)
from amocrm.manager import exchange_code, get_client
# OAuth callback view
exchange_code(subdomain="your-company", code=request.GET["code"], oauth=oauth)
# В любом месте приложения
client = get_client(subdomain="your-company", oauth=oauth)
Кастомное хранилище токенов
from amocrm import TokenStorage
class RedisTokenStorage:
def save(self, access_token: str, refresh_token: str) -> None:
redis.set("amo:access", access_token)
redis.set("amo:refresh", refresh_token)
def load(self) -> tuple[str, str]:
return redis.get("amo:access"), redis.get("amo:refresh")
Работа с ресурсами
# Сделки — авто-пагинация (обходит все страницы, возвращает Iterator)
for lead in client.leads.list():
print(lead.id, lead.name, lead.price)
# Одна страница — передайте page явно
leads = client.leads.list(page=1, limit=50)
# get() автоматически подгружает контакты (with=contacts по умолчанию)
lead = client.leads.get(42)
print(lead.contacts) # list[Contact] | None
lead.price = 9000
client.leads.update_one(lead.id, lead)
new_lead = Lead(name="Big Deal", price=50000, tags=[Tag(name="vip")])
created = client.leads.create([new_lead])
print(created[0].id)
# Создать сделку вместе с контактом и компанией (max 1 контакт, max 50 сделок)
from amocrm import Contact, Company
lead = Lead(
name="Complex Deal",
contacts=[Contact(name="Иван Иванов")],
company=Company(name="ООО Ромашка"),
)
client.leads.create_complex([lead])
# Контакты — авто-пагинация
for contact in client.contacts.list(query="Иван"):
print(contact.name)
client.contacts.create([Contact(name="Иван Иванов", first_name="Иван")])
# Компании — авто-пагинация
for company in client.companies.list():
print(company.name)
client.companies.create([Company(name="Рога и копыта")])
# Задачи — авто-пагинация
from amocrm import Task
for task in client.tasks.list():
print(task.id, task.text, task.complete_till)
task = client.tasks.get(10)
task.text = "Updated text"
client.tasks.update_one(task.id, task)
new_task = Task(text="Call client", task_type_id=1, complete_till=1700000000, entity_id=lead.id, entity_type="leads")
created = client.tasks.create([new_task])
print(created[0].id)
Пагинация
Методы list() у всех ресурсов поддерживают два режима:
| Вызов | Поведение | Возвращает |
|---|---|---|
client.leads.list() |
Авто-пагинация — обходит все страницы | Iterator[Lead] |
client.leads.list(page=2) |
Одна конкретная страница | list[Lead] |
По умолчанию авто-пагинация запрашивает по 50 элементов на страницу. Для кастомного размера: client.leads.list(limit=250).
Models
| Класс | Описание |
|---|---|
Lead |
Сделка. Поля: id, name, price, status_id, pipeline_id, tags, custom_fields_values, contacts, company, … |
Contact |
Контакт. Поля: id, name, first_name, last_name, tags, custom_fields_values, … |
Company |
Компания. Поля: id, name, tags, custom_fields_values, … |
Task |
Задача. Поля: id, text, complete_till, task_type_id, responsible_user_id, is_completed, entity_id, entity_type, result, … |
Tag |
Тег. Поля: id, name |
CustomFieldValue |
Значение кастомного поля. Поля: field_id, values |
Pipeline |
Воронка. Поля: id, name, statuses |
Все модели — @dataclass с методами from_dict / to_dict. to_dict() исключает None-поля, что даёт чистый API payload.
Features
- OAuth2 с auto-refresh токенов по 401
- Гибкое хранилище токенов — любой класс с
save()/load()(Django ORM, Redis, etc.) DjangoTokenStorageиз коробки- Глобальный менеджер (
exchange_code/get_client) для Django/Flask - Typed DTO models — никаких сырых словарей
- Leads (сделки): list, get, create, update, update_one, create_complex;
get()подгружает контакты по умолчанию; лимит 50 сделок за запрос - Contacts (контакты): list, get, create, update, update_one
- Companies (компании): list, get, create, update, update_one
- Pipelines (воронки): list, get, create, update, delete + statuses CRUD
- Tasks (задачи): list, get, create, update, update_one
- Custom fields support
- Авто-пагинация —
list()безpageавтоматически обходит все страницы и возвращаетIterator[T]
Links
TODO
- https://www.amocrm.ru/developers/content/api/recommendations
- https://www.amocrm.ru/developers/content/crm_platform/account-info
https://www.amocrm.ru/developers/content/crm_platform/leads-api- https://www.amocrm.ru/developers/content/crm_platform/unsorted-api
https://www.amocrm.ru/developers/content/crm_platform/leads_pipelines- https://www.amocrm.ru/developers/content/crm_platform/filters-api
https://www.amocrm.ru/developers/content/crm_platform/contacts-apihttps://www.amocrm.ru/developers/content/crm_platform/companies-api- https://www.amocrm.ru/developers/content/crm_platform/catalogs-api
- https://www.amocrm.ru/developers/content/crm_platform/entity-links-api
https://www.amocrm.ru/developers/content/crm_platform/tasks-api- https://www.amocrm.ru/developers/content/crm_platform/custom-fields
- https://www.amocrm.ru/developers/content/crm_platform/tags-api
- https://www.amocrm.ru/developers/content/crm_platform/events-and-notes
- https://www.amocrm.ru/developers/content/crm_platform/customers-api
- https://www.amocrm.ru/developers/content/crm_platform/customers-statuses-api
- https://www.amocrm.ru/developers/content/crm_platform/users-api
- https://www.amocrm.ru/developers/content/crm_platform/products-api
- https://www.amocrm.ru/developers/content/crm_platform/webhooks-api
- https://www.amocrm.ru/developers/content/crm_platform/widgets-api
- https://www.amocrm.ru/developers/content/crm_platform/calls-api
- https://www.amocrm.ru/developers/content/crm_platform/talks-api
- https://www.amocrm.ru/developers/content/crm_platform/subscriptions-api
- https://www.amocrm.ru/developers/content/crm_platform/sources-api
- https://www.amocrm.ru/developers/content/api/salesbot-api
- https://www.amocrm.ru/developers/content/crm_platform/short_links
- https://www.amocrm.ru/developers/content/crm_platform/chat-templates-api
- https://www.amocrm.ru/developers/content/crm_platform/duplication-control
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file amocrm_sdk-0.3.0.tar.gz.
File metadata
- Download URL: amocrm_sdk-0.3.0.tar.gz
- Upload date:
- Size: 8.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9260a1450b04ce051b431e018e76a307008a935fd6fb1f9fe122c39a9099502
|
|
| MD5 |
914af978555645bff160428808a39eee
|
|
| BLAKE2b-256 |
49d94c088ed2e7741c8f1f3319f379ae693cd4c97b5b75f641101567b3916459
|
Provenance
The following attestation bundles were made for amocrm_sdk-0.3.0.tar.gz:
Publisher:
publish.yml on MikhailMurashov/amocrm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
amocrm_sdk-0.3.0.tar.gz -
Subject digest:
a9260a1450b04ce051b431e018e76a307008a935fd6fb1f9fe122c39a9099502 - Sigstore transparency entry: 1107675735
- Sigstore integration time:
-
Permalink:
MikhailMurashov/amocrm-sdk@c973597b8e4d125779ede0aa4bba89426f67404f -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/MikhailMurashov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c973597b8e4d125779ede0aa4bba89426f67404f -
Trigger Event:
release
-
Statement type:
File details
Details for the file amocrm_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: amocrm_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8bd761f2882ae9c7b99ad4bae1e5754b8773d2b6840b2063a59194f105bc6c0
|
|
| MD5 |
6a45d3a483677788a173d4e9c011cb38
|
|
| BLAKE2b-256 |
e505b1f032fa63517d63cabb655f20a6e6e869b92024d0dd0a70d97d1dc5d18b
|
Provenance
The following attestation bundles were made for amocrm_sdk-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on MikhailMurashov/amocrm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
amocrm_sdk-0.3.0-py3-none-any.whl -
Subject digest:
a8bd761f2882ae9c7b99ad4bae1e5754b8773d2b6840b2063a59194f105bc6c0 - Sigstore transparency entry: 1107675738
- Sigstore integration time:
-
Permalink:
MikhailMurashov/amocrm-sdk@c973597b8e4d125779ede0aa4bba89426f67404f -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/MikhailMurashov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c973597b8e4d125779ede0aa4bba89426f67404f -
Trigger Event:
release
-
Statement type: