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
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.2.0.tar.gz.
File metadata
- Download URL: amocrm_sdk-0.2.0.tar.gz
- Upload date:
- Size: 8.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba12eaf14c1febc07772d0104de83aef0b14346a582c8755ae5e058e9fcd7a54
|
|
| MD5 |
5707e8d2c70c816fd7d6bea079edf3eb
|
|
| BLAKE2b-256 |
b10b5e8312814d7d52904d54cdb1f159a53a38d6efcd8c6e5165b925443b3400
|
Provenance
The following attestation bundles were made for amocrm_sdk-0.2.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.2.0.tar.gz -
Subject digest:
ba12eaf14c1febc07772d0104de83aef0b14346a582c8755ae5e058e9fcd7a54 - Sigstore transparency entry: 1092398304
- Sigstore integration time:
-
Permalink:
MikhailMurashov/amocrm-sdk@a85a2bbc5e5d5de6fd90ff37a1fe5c658e22a4af -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MikhailMurashov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a85a2bbc5e5d5de6fd90ff37a1fe5c658e22a4af -
Trigger Event:
release
-
Statement type:
File details
Details for the file amocrm_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: amocrm_sdk-0.2.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 |
f25fd30ca4c37c92ed574c84e637f58afbf4891e5d7427838cb45fc33794d66e
|
|
| MD5 |
67476f57e93c8546cc4af1ff306841bc
|
|
| BLAKE2b-256 |
ea64c13204737a87c983945565f29664e6d112568d562db80a904bf05bbc56de
|