Skip to content

Commit ab8c5e6

Browse files
authored
Merge pull request #21 from akopdev/support-async
Major upgrade to v2
2 parents 0a30bf0 + cd398db commit ab8c5e6

19 files changed

+624
-290
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[run]
2+
omit =
3+
tests/*
4+
setup.py

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 100
3+
max-complexity = 10

.github/workflows/main.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Verify
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.10"
26+
- name: Setup environment
27+
run: |
28+
make init
29+
- name: Install dependencies
30+
run: |
31+
make install
32+
- name: Lint
33+
run: |
34+
make lint
35+
- name: Test
36+
run: |
37+
make test

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Set up Python
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
with:
38+
user: __token__
39+
password: ${{ secrets.PYPI_API_TOKEN }}

Makefile

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
.NOTPARALLEL: ; # wait for this target to finish
2+
.EXPORT_ALL_VARIABLES: ; # send all vars to shell
3+
.PHONY: all # All targets are accessible for user
4+
.DEFAULT: help # Running Make will run the help target
5+
6+
PYTHON = @.venv/bin/python -m
7+
APP = bitrix24
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# help: @ List available tasks on this project
11+
# -------------------------------------------------------------------------------------------------
12+
help:
13+
@grep -oE '^#.[a-zA-Z0-9]+:.*?@ .*$$' $(MAKEFILE_LIST) | tr -d '#' |\
14+
awk 'BEGIN {FS = ":.*?@ "}; {printf " make%-10s%s\n", $$1, $$2}'
15+
16+
# -------------------------------------------------------------------------------------------------
17+
# all: @ Apply all checks at once
18+
# -------------------------------------------------------------------------------------------------
19+
all: format lint test
20+
21+
# -------------------------------------------------------------------------------------------------
22+
# init: @ Setup local environment
23+
# -------------------------------------------------------------------------------------------------
24+
init: activate install
25+
26+
# -------------------------------------------------------------------------------------------------
27+
# update: @ Update package dependencies and install them
28+
# -------------------------------------------------------------------------------------------------
29+
update: compile install
30+
31+
# -------------------------------------------------------------------------------------------------
32+
# Activate virtual environment
33+
# -------------------------------------------------------------------------------------------------
34+
activate:
35+
@python3 -m venv .venv
36+
@. .venv/bin/activate
37+
38+
# -------------------------------------------------------------------------------------------------
39+
# Install packages to current environment
40+
# -------------------------------------------------------------------------------------------------
41+
install:
42+
$(PYTHON) pip install -e .[dev]
43+
44+
# -------------------------------------------------------------------------------------------------
45+
# test: @ Run tests using pytest
46+
# -------------------------------------------------------------------------------------------------
47+
test:
48+
$(PYTHON) pytest tests --cov=.
49+
50+
# -------------------------------------------------------------------------------------------------
51+
# lint: @ Checks the source code against coding standard rules and safety
52+
# -------------------------------------------------------------------------------------------------
53+
lint: lint.setup lint.flake8 lint.safety lint.docs
54+
55+
# -------------------------------------------------------------------------------------------------
56+
# format: @ Format source code and auto fix minor issues
57+
# -------------------------------------------------------------------------------------------------
58+
format:
59+
$(PYTHON) black --quiet --line-length=100 $(APP)
60+
$(PYTHON) isort $(APP)
61+
62+
# -------------------------------------------------------------------------------------------------
63+
# setup.py
64+
# -------------------------------------------------------------------------------------------------
65+
lint.setup:
66+
$(PYTHON) setup check -s
67+
68+
# -------------------------------------------------------------------------------------------------
69+
# flake8
70+
# -------------------------------------------------------------------------------------------------
71+
lint.flake8:
72+
$(PYTHON) flake8 --exclude=.venv,.eggs,*.egg,.git,migrations,__init__.py \
73+
--filename=*.py,*.pyx \
74+
--max-line-length=100 .
75+
76+
# -------------------------------------------------------------------------------------------------
77+
# safety
78+
# -------------------------------------------------------------------------------------------------
79+
lint.safety:
80+
$(PYTHON) safety check --full-report
81+
82+
# -------------------------------------------------------------------------------------------------
83+
# pydocstyle
84+
# -------------------------------------------------------------------------------------------------
85+
# Ignored error codes:
86+
# D100 Missing docstring in public module
87+
# D101 Missing docstring in public class
88+
# D102 Missing docstring in public method
89+
# D103 Missing docstring in public function
90+
# D104 Missing docstring in public package
91+
# D105 Missing docstring in magic method
92+
# D106 Missing docstring in public nested class
93+
# D107 Missing docstring in __init__
94+
lint.docs:
95+
$(PYTHON) pydocstyle --convention=numpy --add-ignore=D100,D101,D102,D103,D104,D105,D106,D107 .
96+
97+
# -------------------------------------------------------------------------------------------------
98+
# clean: @ Remove artifacts and temp files
99+
# -------------------------------------------------------------------------------------------------
100+
clean:
101+
@rm -rf .venv/ dist/ build/ *.egg-info/ .pytest_cache/ .coverage coverage.xml
102+
@find . | grep -E "\(__pycache__|\.pyc|\.pyo\$\)" | xargs rm -rf

README.md

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,75 @@ Easy way to communicate with bitrix24 portal over REST without OAuth 2.0
44

55
## Description
66

7-
Bitrix24 REST is a simple API wrapper for working with Bitrix24
8-
REST API over webhooks.
7+
Bitrix24 REST is an API wrapper for working with Bitrix24 REST API over webhooks.
8+
No OAuth 2.0 required. It's easy to use and super lightweight, with minimal dependencies.
99

1010
## Features
1111

12-
- Works both with cloud and on-premises versions of bitrix24, much more
13-
- Super easy for setting up. No OAuth implemetation required
14-
- Compatible with latests Bitrix24 REST API
15-
16-
## Requirements
17-
- Python 2.6+ or 3.2+
18-
- requests
12+
- Works with both cloud and on-premises versions of Bitrix24.
13+
- Super easy to setup. No OAuth 2.0 infrastructure required.
14+
- Built with data analysis in mind and fully compatible with Jupyter Notebook.
15+
- Fetch paginated data at once without hassle.
16+
- Works with large datasets and handles rate limits.
1917

2018
## Installation
19+
2120
```
2221
pip install bitrix24-rest
2322
```
2423

2524
## Quickstart
2625

2726
```python
28-
from bitrix24 import *
27+
from bitrix24 import Bitrix24
2928

3029
bx24 = Bitrix24('https://example.bitrix24.com/rest/1/33olqeits4avuyqu')
3130

3231
print(bx24.callMethod('crm.product.list'))
3332
```
3433

35-
## Advanced usage
36-
37-
You can define filters and additional parameters in any order:
34+
In async mode:
3835

3936
```python
40-
bx24.callMethod('crm.deal.list',
41-
order={'STAGE_ID': 'ASC'},
42-
filter={'>PROBABILITY': 50},
43-
select=['ID', 'TITLE', 'STAGE_ID', 'PROBABILITY'])
44-
```
37+
import asyncio
38+
from bitrix24 import bitrix24
4539

46-
Catch the server error with exception:
40+
async def main():
41+
bx24 = Bitrix24('https://example.bitrix24.com/rest/1/33olqeits4avuyqu')
42+
result = await bx24.callMethod('crm.product.list')
43+
print(result)
4744

48-
```python
49-
try:
50-
bx24.callMethod('tasks.task.add', fields={'TITLE': 'task for test', 'RESPONSIBLE_ID': 1})
51-
except BitrixError as message:
52-
print(message)
45+
asyncio.run(main())
5346
```
5447

48+
## Advanced usage
49+
50+
- [Using filters and additional parameters](docs/using-filters-and-additional-parameters.md)
51+
- [Working with large datasets](docs/working-with-large-datasets.md)
52+
- [Disabling certificate verification](docs/disabling-certificate-verification.md)
53+
5554
## Notes
56-
List methods return all available items at once. For large collections
57-
of data use limits.
5855

59-
## Tests
56+
List methods return all available items at once. For large collections of data use limits.
6057

58+
## Development
59+
60+
New contributers and pull requests are welcome. If you have any questions or suggestions, feel free to open an issue.
61+
62+
Code comes with makefile for easy code base management. You can check `make help` for more details.
63+
64+
```sh
65+
make init install # to create a local virtual environment and install dependencies
66+
67+
make test # to run tests
68+
69+
make lint # to run linter
6170
```
62-
python -m unittest discover
63-
```
6471

65-
## Author
72+
I suggest to use `make all` before committing your changes as it will run all the necessary checks.
73+
74+
## Support this project
6675

67-
Akop Kesheshyan - <akop.kesheshyan@icloud.com>
76+
You can support this project by starring ⭐, sharing 📤, and contributing.
6877

69-
New contributers and pull requests are welcome.
78+
You can also support the author by buying him a coffee ☕. Click sponsor button on the top of the page.

bitrix24/__init__.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
# -*- coding: utf-8 -*-
2-
31
# ____ _ _ _ ____ _ _ ____ _____ ____ _____
42
# | __ )(_) |_ _ __(_)_ _|___ \| || | | _ \| ____/ ___|_ _|
53
# | _ \| | __| '__| \ \/ / __) | || |_ | |_) | _| \___ \ | |
64
# | |_) | | |_| | | |> < / __/|__ _| | _ <| |___ ___) || |
75
# |____/|_|\__|_| |_/_/\_\_____| |_| |_| \_\_____|____/ |_|
86

9-
10-
"""
11-
Bitrix24 REST library
12-
~~~~~~~~~~~~~~~~~~~~~
13-
14-
Bitrix24 REST provides easy way to communicate with bitrix24 portal over REST without OAuth 2.0.
15-
usage:
16-
17-
>>> from bitrix24 import Bitrix24
18-
>>> bx24 = Bitrix24('https://example.bitrix24.com/rest/1/33olqeits4avuyqu')
19-
>>> r = bx24.callMethod('crm.product.list')
20-
21-
Copyright (c) 2019 by Akop Kesheshyan.
22-
"""
23-
24-
__version__ = '1.1.1'
25-
__author__ = 'Akop Kesheshyan <akop.kesheshyan@icloud.com>'
26-
__license__ = 'MIT'
27-
__copyright__ = 'Copyright 2019 Akop Kesheshyan'
28-
297
from .bitrix24 import Bitrix24
30-
from .exceptions import BitrixError
8+
from .exceptions import BitrixError
9+
10+
__all__ = ["Bitrix24", "BitrixError"]

0 commit comments

Comments
 (0)