Giter Club home page Giter Club logo

pybitrix's Introduction

PyBitrix

version

downloads


PyBitrix is my lightweight implementation of Bitrix 24 REST API wrapper that I use in my own applications/integrations

Requirements

  • Python 3.6+
  • requests
  • aiohttp

Quick start

Install package from pip

pip3 install pybitrix

Then create PyBitrix instance

from pybitrix import PyBitrix

# for webhook usage
webhook = "https://You/hook from/bitrix/developers panel/"
b24 = PyBitrix(inbound_hook=webhook)

# for use as application (with tokens)
domain = "BX DOMAIN (eg. some-stuff.bitrix.ru). Can be taken from bitrix request to your app"
auth_id = "ACCESS_TOKEN_TAKEN_FROM_BITRIX_REQUEST_TO_YOUR_APP"
refresh_id = "REFRESH_TOKEN_TAKEN_FROM_BITRIX_REQUEST_TO_YOUR_APP"
app_id = "APP_ID_FROM_MARKETPLACE_OR_LOCAL_APP_INSTALLATION"
app_secret = "SECRET_KEY_FROM_MARKETPLACE_OR_LOCAL_APP_INSTALLATION"
b24 = PyBitrix(domain=domain, access_token=auth_id, refresh_token=refresh_id, app_id=app_id, app_secret=app_secret)

Make call

bx24.call('crm.contact.list', {
    'order': ['DSC'],
    'select': ['TITLE', 'DATE_CREATE'],
    'filter': {"<ID": 50}
})

Make batch call

batch={
    'contacts': 'crm.contact.list', 
    'deals': 'crm.deal.list'
}
batchParams={
    'contacts': [
        'select[]=TITLE', 
        'order[ID]=DSC', 
        'filter[>ID]=15'
    ], 'deals' : [
        'select[]=TITLE',
        'select[]=STAGE_ID'
    ]
}
response = bx24.callBatch(batch=batch, batchParams=batchParams)
print("CONTACTS: {}".format(response['result']['result']['contacts']))
print("DEALS: {}".format(response['result']['result']['deals']))

Renew tokens

PyBitrix refreshes tokens automatically, but if you want to do this manually, you should call method refresh_tockens()

bx24.refresh_tokens()

asyncio + aiohttp

To use async version, you need to just import PyBitrixAsync

    from pybitrix import PyBitrixAsync
    b24 = PyBitrixAsync(...)
    result = await b24(...)

Todos

  • More comfortable batchParams collector
  • Fast lists uploading via 'start': -1

License

MIT

pybitrix's People

Contributors

dkeysil avatar momoru-kun avatar msitetop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

msitetop

pybitrix's Issues

AttributeError: module 'aiohttp' has no attribute 'exceptions'

Python 3.11

from pybitrix import PyBitrixAsync

...

bitrix = PyBitrixAsync(...)

await bitrix.call('placement.bind', {
    'PLACEMENT': 'SONET_GROUP_DETAIL_TAB',
    'HANDLER': f"https://{APP_URL}",
    'TITLE': 'title',
    'DESCRIPTION': 'desc',
})
AttributeError: module 'aiohttp' has no attribute 'exceptions'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.