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")
Работа с ресурсами
# Сделки
leads = client.leads.list(page=1, limit=50)
for lead in leads:
print(lead.id, lead.name, lead.price)
lead = client.leads.get(42)
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)
# Контакты
contacts = client.contacts.list(query="Иван")
client.contacts.create([Contact(name="Иван Иванов", first_name="Иван")])
# Компании
companies = client.companies.list(page=1, limit=25)
client.companies.create([Company(name="Рога и копыта")])
Models
| Класс | Описание |
|---|---|
Lead |
Сделка. Поля: id, name, price, status_id, pipeline_id, tags, custom_fields_values, … |
Contact |
Контакт. Поля: id, name, first_name, last_name, tags, custom_fields_values, … |
Company |
Компания. Поля: id, name, tags, custom_fields_values, … |
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
- Contacts (контакты): list, get, create, update, update_one
- Companies (компании): list, get, create, update, update_one
- Pipelines (воронки): list, get, create, update, delete + statuses CRUD
- Custom fields support
- Pagination helpers
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
amocrm_sdk-0.1.0.tar.gz
(8.3 MB
view details)
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.1.0.tar.gz.
File metadata
- Download URL: amocrm_sdk-0.1.0.tar.gz
- Upload date:
- Size: 8.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50a1e78063f21e6e84165431c983e356fcc8d053058ba7b80d414d98af23e5d6
|
|
| MD5 |
bbaf01b5e29471c2e62ca78cc215b3d0
|
|
| BLAKE2b-256 |
b6579a40b874ff6504f2637f49ecf42a7b0b99f2e27030b83f1a8aa8c81657a2
|
File details
Details for the file amocrm_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: amocrm_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462043282af7f6c737080415e452daca92ceb13187c036d1ee418fc3f78ebebc
|
|
| MD5 |
08ec62ebdd94ba60629b615d74868468
|
|
| BLAKE2b-256 |
b4eb48080427ba3c8d6d0727bdd07e7997c5fdb037a8218f5457f96b79464533
|