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.
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
withstatements. - Localization: Supports specifying the desired language for API interactions.
- Utility Methods: Format dates, times, and other helper functionalities compliant with SarvCRM standards.
Installation
- Ensure you have Python 3.9+ installed.
- Make Sure pip and git are installed
- Install the package
pip install py-sarvcrm-api
Quick Start
Example Usage
from sarvcrm_api import SarvClient
# Initialize the client
client = SarvClient(
utype="your_instance_utype",
username="your_username",
password="your_password",
language="en_US",
)
# Use as a context manager for clean execution
print(f'Connecting to {client.api_url}')
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', limit=10)
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}')
# Create URL
url = client.Accounts.get_url_detail_view(pk=uid)
print(f'Item link: {url}')
# Delete Item
deleted_item = client.Accounts.delete(uid)
print(f'Deleted item: {deleted_item}')
Class Details
SarvClient
Constructor
SarvClient(
utype: str,
username: str,
password: str,
api_url: str = SarvURL,
frontend_url: str = SarvFrontend,
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:
utype: Utype of your sarvcrm instance.username: Your SarvCRM username.password: Password for authentication.api_url: URL of the Sarvcrm api, if you dont use the cloud version, specify local serverfrontend_url: URL of the Sarvcrm frontend, if you dont use the cloud version, specify local serverlogin_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_outputFormatsdatetimeortimedeltaobjects according to SarvCRM standards. -
loginAuthenticates the user and retrieves an access token. -
logoutClears the session token. -
search_by_numberSearches a module or all modules for records matching a given phone number. -
get_detail_url_by_numberreturns the detail view url of the specified 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: TheSarvClientinstance for API interactions.
Methods
-
createCreates a new record in the module. -
read_listRetrieves a list of items from the module. -
real_list_allRetrieves all items as a list from the module. -
read_recordFetches a single record by ID. -
updateUpdates an existing record. -
deleteDeletes a record by ID. -
get_module_fieldsRetrieves the fields of the module. -
get_relationshipsFetches related items. -
save_relationshipsSaves relationships between records. -
get_url_edit_viewreturns the editview url -
get_url_list_viewreturns list view url -
get_url_detail_viewreturns detail view url
Additional Features
- Error Handling: Raise
SarvExceptionfor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_sarvcrm_api-1.0.1.tar.gz.
File metadata
- Download URL: py_sarvcrm_api-1.0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00e30ac8b5066f51f3c342cb5f997a2b94ef902832f024fa022480818469d551
|
|
| MD5 |
8c6676f1cab49026835375135a96b382
|
|
| BLAKE2b-256 |
575a7dc0013831d93c7fc53812a805a4fc77ae760a12f706d6f731088e619506
|
Provenance
The following attestation bundles were made for py_sarvcrm_api-1.0.1.tar.gz:
Publisher:
python-publish.yml on Radin-System/py-sarvcrm-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_sarvcrm_api-1.0.1.tar.gz -
Subject digest:
00e30ac8b5066f51f3c342cb5f997a2b94ef902832f024fa022480818469d551 - Sigstore transparency entry: 164101017
- Sigstore integration time:
-
Permalink:
Radin-System/py-sarvcrm-api@044b3a1464c900f33f0f4b7717ca2f073ae05da5 -
Branch / Tag:
refs/tags/urls - Owner: https://github.com/Radin-System
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@044b3a1464c900f33f0f4b7717ca2f073ae05da5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file py_sarvcrm_api-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_sarvcrm_api-1.0.1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ab3f97fce7b69b785b56f88cf733b733019abc281b1fd1b8622a0d276dfc162
|
|
| MD5 |
2280407b0990f5426c9445440fc3958f
|
|
| BLAKE2b-256 |
cf5c6c37307c2516ad4fdd888b3aeaf1cb074722da2fb6218528ae12c28a69de
|
Provenance
The following attestation bundles were made for py_sarvcrm_api-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on Radin-System/py-sarvcrm-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_sarvcrm_api-1.0.1-py3-none-any.whl -
Subject digest:
5ab3f97fce7b69b785b56f88cf733b733019abc281b1fd1b8622a0d276dfc162 - Sigstore transparency entry: 164101019
- Sigstore integration time:
-
Permalink:
Radin-System/py-sarvcrm-api@044b3a1464c900f33f0f4b7717ca2f073ae05da5 -
Branch / Tag:
refs/tags/urls - Owner: https://github.com/Radin-System
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@044b3a1464c900f33f0f4b7717ca2f073ae05da5 -
Trigger Event:
release
-
Statement type: