Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aioalfacrm

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aioalfacrm

Is an asynchronous implementation for AlfaCRM API

  • 0.3.2
  • PyPI
  • Socket score

Maintainers
1

AIOAlfacrm

PyPi Package Version Supported python versions MIT License Downloads Codecov Tests

aioalfacrm - is an asynchronous implementation for the AlfaCRM API

Package is in development

Installation using pip

$ pip install aioalfacrm

Example:

import asyncio
from aioalfacrm import AlfaClient
from aioalfacrm.entities import Location

HOSTNAME = 'demo.s20.online'
EMAIL = 'api-email@email.example'
API_KEY = 'user-api-token'
BRANCH_ID = 1


async def main():
    alfa_client = AlfaClient(
        hostname=HOSTNAME,
        email=EMAIL,
        api_key=API_KEY,
        branch_id=BRANCH_ID,
    )
    try:
        # Check auth (Optionaly)
        if not await alfa_client.check_auth():
            print('Authentification error')
            return
        # Get branches
        branches = await alfa_client.branch.list(page=0, count=20)

        # Edit branch
        for branch in branches:
            branch.name = f'{branch.name} - Edited'
            # Save branch
            await alfa_client.branch.save(branch)

        # Create location
        location = Location(
            branch_id=1,
            is_active=True,
            name='New location',
        )
        await alfa_client.location.save(location)

    finally:
        # Close session
        await alfa_client.close()


asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # For Windows
asyncio.run(main())


Paginator

# Get all entities
for page in alfa_client. < object >.get_paginator():
    objects = page.items

Custom fields

To work with custom fields, do the following

from aioalfacrm import entities
from aioalfacrm import fields
from typing import Optional


# Extend existing model
class CustomCustomer(entities.Customer):
    custom_field: Optional[int] = fields.Integer()

    # For IDE init support
    def __init__(
            self,
            custom_field: Optional[int] = None,
            *args,
            **kwargs,
    ):
        super(CustomCustomer, self).__init__(custom_field=custom_field, *args, **kwargs)


# Create custom alfa client with new model
from aioalfacrm import AlfaClient
from aioalfacrm import managers


class CustomAlfaClient(AlfaClient):

    def __init__(self, *args, **kwargs):
        super(CustomAlfaClient, self).__init__(*args, **kwargs)

        self.customer = managers.Customer(
            api_client=self.api_client,
            entity_class=CustomCustomer,
        )


# Create custom alfa client
import asyncio

HOSTNAME = 'demo.s20.online'
EMAIL = 'api-email@email.example'
API_KEY = 'user-api-token'
BRANCH_ID = 1


async def main():
    alfa_client = CustomAlfaClient(hostname=HOSTNAME, email=EMAIL, api_key=API_KEY, branch_id=BRANCH_ID)
    try:
        customers = await alfa_client.customer.list()
        for customer in customers:
            print(customer.custom_field)
    finally:
        await alfa_client.close()


asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # For Windows
asyncio.run(main())

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc