Skip to main content

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

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.2.0.tar.gz (8.3 MB view details)

Uploaded Source

Built Distribution

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

amocrm_sdk-0.2.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

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

Hashes for amocrm_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba12eaf14c1febc07772d0104de83aef0b14346a582c8755ae5e058e9fcd7a54
MD5 5707e8d2c70c816fd7d6bea079edf3eb
BLAKE2b-256 b10b5e8312814d7d52904d54cdb1f159a53a38d6efcd8c6e5165b925443b3400

See more details on using hashes here.

Provenance

The following attestation bundles were made for amocrm_sdk-0.2.0.tar.gz:

Publisher: publish.yml on MikhailMurashov/amocrm-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for amocrm_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f25fd30ca4c37c92ed574c84e637f58afbf4891e5d7427838cb45fc33794d66e
MD5 67476f57e93c8546cc4af1ff306841bc
BLAKE2b-256 ea64c13204737a87c983945565f29664e6d112568d562db80a904bf05bbc56de

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