### Install Core and Development Dependencies Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Installs the main Python packages for the project and its development tools. Ensure Python 3.7+ is installed. ```bash # Python version Python 3.7+ # Core dependencies aiohttp>=3.8.0 tqdm>=4.64.0 beartype>=0.9.0 icontract>=2.6.0 # Development dependencies pytest>=6.0.0 pytest-asyncio>=0.18.0 pytest-cov>=3.0.0 black>=22.0.0 flake8>=4.0.0 mypy>=0.950 ``` -------------------------------- ### Install and Test fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Installs the project in development mode and runs the test suite with coverage. Requires pip and pytest. ```bash # Development installation pip install -e . # Install development dependencies pip install -r requirements.txt # Run tests pytest # Run with coverage pytest --cov=fast_bitrix24 ``` -------------------------------- ### Observer Pattern for Progress Tracking Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Example of using `tqdm` to display a progress bar during request execution, demonstrating the Observer pattern. ```python # Progress bar updates during request execution with tqdm(total=total_items) as pbar: # Update progress as requests complete ``` -------------------------------- ### Optional Python Dependencies Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Lists optional Python packages that can be installed for enhanced performance monitoring and logging. ```python # Performance monitoring psutil>=5.8.0 # Advanced logging structlog>=21.0.0 ``` -------------------------------- ### Format Code with Black Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Applies automatic code formatting to the specified directories using the Black tool. Ensure Black is installed. ```bash black fast_bitrix24/ tests/ ``` -------------------------------- ### List and Get CRM Leads Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/speed_tests/strategies.ipynb Retrieves all CRM leads using the `list_and_get` method, which is a convenience method for fetching all items of a given entity. This is demonstrated for both clients, one respecting and one ignoring the velocity policy. ```python respect = await bx_respect.list_and_get('crm.lead') ignore = await bx_ignore.list_and_get('crm.lead') ``` -------------------------------- ### Lint Code with Flake8 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Performs linting and style checking on the project files using Flake8. Ensure Flake8 is installed. ```bash flake8 fast_bitrix24/ tests/ ``` -------------------------------- ### Type Check Code with MyPy Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Conducts static type checking on the project's Python code using MyPy. Ensure MyPy is installed. ```bash mypy fast_bitrix24/ ``` -------------------------------- ### Synchronous Client Initialization Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Initialize the synchronous `Bitrix` client for traditional Python code. This wrapper handles automatic async-to-sync conversion. ```python from fast_bitrix24 import Bitrix bx24 = Bitrix('https://your_domain.bitrix24.com', 'your_access_token') ``` -------------------------------- ### Async-First with Sync Wrapper Architecture Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Illustrates the core architecture where BitrixAsync handles core async implementation and Bitrix provides a synchronous wrapper. ```text Bitrix (Sync Wrapper) ↓ (decorates with sync wrapper) BitrixAsync (Core Implementation) ↓ (uses) ServerRequestHandler (Request Management) ↓ (uses) Throttle (Rate Limiting) ``` -------------------------------- ### Project Structure Overview Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Illustrates the directory layout for the fast_bitrix24 project, including main package modules, tests, and configuration files. ```text fast_bitrix24/ ├── fast_bitrix24/ # Main package │ ├── __init__.py # Package exports │ ├── bitrix.py # Main client classes │ ├── srh.py # ServerRequestHandler │ ├── throttle.py # Rate limiting │ ├── user_request.py # Request strategies │ ├── server_response.py # Response parsing │ ├── logger.py # Logging utilities │ ├── mult_request.py # Parallel requests │ └── utils.py # Utility functions ├── tests/ # Test suite │ ├── conftest.py # Test configuration │ ├── test_*.py # Test modules │ └── real_responses/ # Mock response data ├── speed_tests/ # Performance benchmarks ├── setup.py # Package configuration ├── requirements.txt # Dependencies ├── README.md # User documentation ├── API.md # API reference └── CONTRIBUTING.md # Contribution guidelines ``` -------------------------------- ### Asynchronous Client Initialization Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Initialize the asynchronous `BitrixAsync` client for async/await operations. It provides full async support for all methods and manages event loop integration. ```python from fast_bitrix24 import BitrixAsync async def main(): bx24 = BitrixAsync('https://your_domain.bitrix24.com', 'your_access_token') # ... your async operations here import asyncio asyncio.run(main()) ``` -------------------------------- ### Configure fast_bitrix24 for Enterprise Optimization Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/productContext.md Initialize the Bitrix client with custom `request_pool_size` and `requests_per_second` to optimize performance for enterprise accounts. Adjust these parameters based on your Bitrix24 plan and network conditions. ```python bx = Bitrix(webhook, request_pool_size=250, requests_per_second=5) ``` -------------------------------- ### Initialize Bitrix24 API Clients Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/speed_tests/strategies.ipynb Initializes two asynchronous Bitrix24 clients. One client respects the velocity policy, while the other ignores it. This is useful for testing rate limiting behavior. ```python from webhook import webhook from fast_bitrix24 import BitrixAsync from asyncio import sleep bx_respect = BitrixAsync(webhook, respect_velocity_policy=True) bx_ignore = BitrixAsync(webhook, respect_velocity_policy=False) ``` -------------------------------- ### Request Creation Factory Pattern Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Illustrates the factory pattern for creating appropriate request objects based on method and parameters. ```python # Request creation based on method and parameters request = self._create_request(method, params) ``` -------------------------------- ### Retrieve All Leads with fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/productContext.md Use `get_all` to retrieve all records for a given method, simplifying data fetching for large datasets. This method handles pagination automatically. ```python from fast_bitrix24 import Bitrix bx = Bitrix(webhook) leads = bx.get_all('crm.lead.list') # One line gets all leads ``` -------------------------------- ### Core Dependencies Structure Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Visual representation of the core directory structure and its main components. ```text fast_bitrix24/ ├── __init__.py (exports Bitrix, BitrixAsync) ├── bitrix.py (main client classes) ├── srh.py (ServerRequestHandler) ├── throttle.py (rate limiting) ├── user_request.py (request strategies) ├── server_response.py (response parsing) ├── logger.py (logging utilities) ├── mult_request.py (parallel request handling) └── utils.py (utility functions) ``` -------------------------------- ### Retrieve All Data with get_all() Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Use the `get_all()` method for complete dataset retrieval. It handles pagination automatically and supports parallel batch execution for high performance. ```python bx24.get_all('user.get') ``` -------------------------------- ### Enable Logging for fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/README.md Enable logging for the fast_bitrix24 library to capture requests and responses. This is useful for debugging and understanding the library's behavior. ```python import logging logging.getLogger('fast_bitrix24').addHandler(logging.StreamHandler()) ``` -------------------------------- ### Decorator Pattern Usage Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Demonstrates the use of decorators for method enhancement, such as logging and validation. ```python @log @beartype async def get_all(self, method: str, params: dict = None): ``` -------------------------------- ### Request Flow Diagram Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Step-by-step flow of a user request from initiation to result. ```text 1. **User calls method** → `Bitrix`/`BitrixAsync` 2. **Parameter validation** → Type checking and validation 3. **Request creation** → Appropriate `UserRequest` class 4. **Batching** → Group requests into batches 5. **Parallel execution** → `ServerRequestHandler` 6. **Rate limiting** → `Throttle` class 7. **Response processing** → `ServerResponseParser` 8. **Error handling** → Exception handling and recovery 9. **Result return** → Processed data to user ``` -------------------------------- ### Direct API Access with call(raw=True) Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Bypass standard batching for direct API access using `call(raw=True)`. This is useful for special cases and supports `None` values in parameters, maintaining compatibility with legacy methods. ```python bx24.call('user.get', {'ID': 1}, raw=True) ``` -------------------------------- ### Efficiently Update Multiple Deals in fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/productContext.md Perform batch updates on multiple records by preparing a list of tasks and using the `call` method. This is significantly more efficient than individual updates. ```python # Update multiple deals efficiently tasks = [ { 'ID': d['ID'], 'fields': {'TITLE': f'{d["ID"]} - {d["TITLE"]}'} } for d in deals ] bx.call('crm.deal.update', tasks) ``` -------------------------------- ### Bash Environment Variables for Development and Testing Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Configure development and testing environments using these bash environment variables. Set DEBUG and LOG_LEVEL for development, and TEST_MODE and MOCK_RESPONSES for testing. ```bash # Development settings FAST_BITRIX24_DEBUG=1 FAST_BITRIX24_LOG_LEVEL=DEBUG # Testing settings FAST_BITRIX24_TEST_MODE=1 FAST_BITRIX24_MOCK_RESPONSES=1 ``` -------------------------------- ### Apply Slowdown Context Manager Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/README.md Use the `slow()` context manager to limit the rate of requests to the Bitrix24 API. This is helpful when encountering server errors due to high load. ```python with bx.slow(): results = bx.call('crm.lead.add', tasks) ``` -------------------------------- ### Execute Batch API Methods with call_batch() Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Utilize `call_batch()` for executing Bitrix24 batch methods. It allows for complex command chaining, handles result dependencies, and isolates errors per command. ```python bx24.call_batch([ bx24.call('user.get', {'ID': 1}), bx24.call('user.get', {'ID': 2}) ]) ``` -------------------------------- ### Request Processing Pipeline Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/systemPatterns.md Outlines the sequence of steps involved in processing a user request through the system. ```text User Request → Parameter Validation → Request Creation → Batching → Parallel Execution → Response Processing → Error Handling → Result ``` -------------------------------- ### Core Python Dependencies Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Lists the essential Python packages required for the core functionality of the fast_bitrix24 project. ```python # HTTP client aiohttp>=3.8.0 # Progress visualization tqdm>=4.64.0 # Type checking and validation beartype>=0.9.0 # Design by contract icontract>=2.6.0 ``` -------------------------------- ### Fetch CRM Leads After Delay Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/speed_tests/strategies.ipynb Waits for 25 seconds to allow the API rate limit to recover, then fetches CRM leads. It first fetches using the client that ignores the velocity policy, followed by the client that respects it. This demonstrates fetching data after a cooldown period. ```python # а теперь дадим пулу восстановиться и попробуем запустить тест в обратном порядке await sleep(25) ignore = await bx_ignore.get_all('crm.lead.list', params={'select': ['ID', 'STAGE_ID']}) respect = await bx_respect.get_all('crm.lead.list', params={'select': ['ID', 'STAGE_ID']}) ``` -------------------------------- ### Perform Async Operations with fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/productContext.md Utilize `BitrixAsync` for asynchronous API calls, allowing your application to remain responsive during long-running operations. Remember to use `await` when calling its methods. ```python from fast_bitrix24 import BitrixAsync bx = BitrixAsync(webhook) leads = await bx.get_all('crm.lead.list') ``` -------------------------------- ### Pytest Fixture for Mocking HTTP Responses Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Use this pytest fixture to mock Bitrix24 API responses for testing purposes. Requires pytest. ```python @pytest.fixture def mock_responses(): # Mock Bitrix24 API responses ``` -------------------------------- ### Development Python Dependencies Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Specifies the Python packages needed for development, testing, and code quality checks. ```python # Testing pytest>=6.0.0 pytest-asyncio>=0.18.0 pytest-cov>=3.0.0 # Code quality black>=22.0.0 flake8>=4.0.0 mypy>=0.950 # Documentation sphinx>=4.0.0 ``` -------------------------------- ### Python Integration Test for API Workflow Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Use this for testing complete end-to-end workflows in Python. Requires pytest and async capabilities. ```python async def test_get_all_integration(): # Test complete workflow ``` -------------------------------- ### Perform Batch Operations with call() Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md The `call()` method is designed for batch operations, automatically grouping requests (up to 50 per batch) and executing them in parallel. It also handles result sorting and error management per request. ```python bx24.call('user.get', {'ID': 1}) bx24.call('user.get', {'ID': 2}) ``` -------------------------------- ### Retrieve Data by ID with get_by_ID() Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/progress.md Efficiently retrieve specific entities using `get_by_ID()`. This method supports custom ID field names and organizes results in a dictionary format. ```python bx24.get_by_ID('user.get', [1, 2, 3]) ``` -------------------------------- ### Fetch CRM Leads Ignoring Velocity Policy Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/speed_tests/strategies.ipynb Fetches a list of CRM leads, selecting only their ID and Stage ID. This call is made using a client configured to ignore the Bitrix24 API velocity policy, potentially leading to rate limiting errors if not managed carefully. ```python ignore = await bx_ignore.get_all('crm.lead.list', params={'select': ['ID', 'STAGE_ID']}) ``` -------------------------------- ### Fetch CRM Leads Respecting Velocity Policy Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/speed_tests/strategies.ipynb Fetches a list of CRM leads, selecting only their ID and Stage ID. This call is made using a client configured to respect the Bitrix24 API velocity policy. ```python respect = await bx_respect.get_all('crm.lead.list', params={'select': ['ID', 'STAGE_ID']}) ``` -------------------------------- ### Retrieve Filtered Deals with fast_bitrix24 Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/productContext.md Fetch records based on specific filters and select desired fields using the `get_all` method. This allows for targeted data retrieval, reducing the amount of data processed. ```python deals = bx.get_all( 'crm.deal.list', params={ 'select': ['*', 'UF_*'], 'filter': {'CLOSED': 'N'} } ) ``` -------------------------------- ### Python Performance Test for Large Datasets Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Use this for testing the speed and memory usage with large datasets in Python. Requires pytest. ```python def test_large_dataset_performance(): # Test with large datasets ``` -------------------------------- ### Python Unit Test for Parameter Validation Source: https://github.com/leshchenko1979/fast_bitrix24/blob/master/memory-bank/techContext.md Use this for testing individual component validation logic in Python. Requires pytest. ```python def test_parameter_validation(): # Test parameter validation logic ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.