Skip to main content

Simple sarvcrm api module

Project description

SarvClient API Interaction Module

Overview

The SarvClient module provides a Python interface for interacting with the SarvCRM API. It simplifies authentication, CRUD operations, and module-specific functionalities for seamless integration with SarvCRM.

SarvCRM API Documents

Features

  • Authentication: Log in and manage sessions with the SarvCRM API.
  • CRUD Operations: Perform Create, Read, Update, and Delete transactions via simple methods.
  • Context Manager Support: Automatically handle login and logout within with statements.
  • Localization: Supports specifying the desired language for API interactions.
  • Utility Methods: Format dates, times, and other helper functionalities compliant with SarvCRM standards.

Installation

  1. Ensure you have Python 3.11+ installed.
  2. Make Sure pip and git are installed
  3. Install the package
    pip install py-sarvcrm-api
    

Quick Start

Example Usage

from sarvcrm_api import SarvClient, SarvURL

# SarvURL = 'https://app.sarvcrm.com/API.php'

# Initialize the client
client = SarvClient(
    base_url=SarvURL, # you can specify your own url if you have local server
    utype="youre_instance_utype",
    username="your_username",
    password="your_password",
    language="en_US"
)

# Use as a context manager for clean execution
print(f'Connecting to {SarvURL}')
with client:
    # Create new item in Accounts
    uid = client.Accounts.create(type='Corporate', name='RadinSystem', numbers=['02145885000'])
    print(f'New Account Created: {uid}')
    
    # Read one item record
    record = clinet.Accounts.read_record(uid)
    print(f'Single Account record: {record}')

    # Read List of items
    records = client.Accounts.read_list(order_by='name')
    print('Accounts list:')
    for account in Accounts:
        print(f' - {account}')

    # Update an item
    updated_item = client.Accounts.update(uid, name='Radin-System')
    print(f'Updated item id: {updated_item}')

    # Search for data by phone number
    result = client.search_by_number(number="02145885000", module=client.Accounts) # module is optional
    print(f'Search by number result: {result}')

    # Delete Item
    deleted_item = client.Accounts.delete(uid)
    print(f'Deleted item: {deleted_item}')

Class Details

SarvClient

Constructor

SarvClient(
    base_url: str,
    utype: str,
    username: str,
    password: str,
    login_type: Optional[str] = None, # eg. 'portal' for portal users
    language: str = "en_US", # Options: fa_IR, en_US
    is_password_md5: bool = False
)

Parameters:

  • base_url: The base URL for the SarvCRM API.
  • utype: Utype of your sarvcrm instance.
  • username: Your SarvCRM username.
  • password: Password for authentication.
  • login_type: (Optional) Login type for advanced configurations.
  • language: Language code (default: en_US).
  • is_password_md5: Whether the password is already MD5-hashed.

Methods

iso_time_output

Formats datetime or timedelta objects according to SarvCRM standards.

login

Authenticates the user and retrieves an access token.

logout

Clears the session token.

search_by_number

Searches a module or all modules for records matching a given phone number.


Attributes:

  • Accounts, AosContracts, AosInvoices, AosPdfTemplates, etc.: Module instances for various SarvCRM functionalities.

Description: Initializes all the modules as attributes of the ModulesMixin class for easy access.


SarvModule

Constructor

SarvModule(_client: SarvClient)

Attributes:

  • _module_name: The name of the module.
  • _label_en: The label of the module in English.
  • _label_pr: The label of the module in Persian.
  • _client: The SarvClient instance for API interactions.

Methods

  • create(**KWArgs) -> str Creates a new record in the module.

  • read_list(query: Optional[str] = None, order_by: Optional[str] = None, select_fields: Optional[list[str]] = None, limit: int = None, offset: int = None) -> list Retrieves a list of items from the module.

  • real_list_all(query: Optional[str] = None, order_by: Optional[str] = None, select_fields: Optional[list[str]] = None, item_buffer: int = 300) -> list Retrieves all items as a list from the module.

  • read_record(pk: str) -> dict Fetches a single record by ID.

  • update(pk: str, **fields_data) -> str Updates an existing record.

  • delete(pk: str) -> str | None Deletes a record by ID.

  • get_module_fields() -> dict[str, dict] Retrieves the fields of the module.

  • get_relationships(related_field: str, query: Optional[str] = None, order_by: Optional[str] = None, select_fields: Optional[list[str]] = None, limit: int = None, offset: int = None) -> list Fetches related items.

  • save_relationships(pk: str, field_name: str, related_records: list) -> list Saves relationships between records.


Additional Features

  • Error Handling: Raise SarvException for API errors.
  • Secure Defaults: Passwords are hashed with MD5 unless explicitly provided as pre-hashed.

License

This module is licensed for Radin System. For details, see the LICENSE file.

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

py_sarvcrm_api-0.1.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

py_sarvcrm_api-0.1.2-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file py_sarvcrm_api-0.1.2.tar.gz.

File metadata

  • Download URL: py_sarvcrm_api-0.1.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for py_sarvcrm_api-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eba4a91c316d21e2f8c135eeefb8f479ff69f9f7d109dda3d0b1ba8101641de6
MD5 7cd700c6c08f6a263622fb8700bc01c2
BLAKE2b-256 0f7b0e78af8a1339884dbb02a531e5c88295d94e7f29011de245562bdbc0145a

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_sarvcrm_api-0.1.2.tar.gz:

Publisher: python-publish.yml on Radin-System/py-sarvcrm-api

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

File details

Details for the file py_sarvcrm_api-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_sarvcrm_api-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for py_sarvcrm_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd2c954e2e1b7b05fb47437f5c33ed345b848ee4d3d1ac3ddcf4389bb6fecf7
MD5 95757dae9b476b9143fbb1a2df884b3a
BLAKE2b-256 9b37bc1ebc92c5c8cd2609bc0900bee9f2cd1a5700cc9382d9bdd9e5c47689be

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_sarvcrm_api-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on Radin-System/py-sarvcrm-api

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

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