ORM for Custom Objects de Zendesk
Project description
Mercury (ORM Zendesk CustomObjects)
Mercury is a Python ORM (Object-Relational Mapping) designed to integrate seamlessly with the Zendesk Custom Objects API. It provides a Django-like interface for defining, managing, and interacting with Zendesk custom objects and records, simplifying the communication with Zendesk's API.
Key Features
- Custom Object Representation: Define Zendesk custom objects using Python classes.
- Automatic Record Management: Built-in methods for creating, reading, updating, and deleting records via Zendesk's API.
- Support for All Field Types: Compatible with all Zendesk custom field types including text, dropdown, checkbox, date, integer, and more.
- Automatic Object Creation: Automatically create Zendesk custom objects and fields from Python class definitions.
- Easy Record Operations: Simple API to manage custom object records, with built-in support for querying, filtering, and pagination.
Installation
pip install mercury-orm
# add variables in .env or:
export ZENDESK_SUBDOMAIN=<your_zendesk_subdomain>.
export ZENDESK_API_TOKEN=<your_zendesk_api_token>.
export ZENDESK_EMAIL=<your_zendesk_email>.
CRUD Operations with Records
Mercury ORM provides simple methods for performing CRUD (Create, Read, Update, Delete) operations on Zendesk custom object records. Below are examples of how to manage records in your custom objects.
Creating a CustomObjects
class Product(CustomObject):
name = fields.TextField("name")
code = fields.TextField("code")
descricao = fields.TextareaField("descricao")
price = fields.DecimalField("price")
active = fields.CheckboxField("active")
voltage = fields.DropdownField("voltage", choices=["220", "110", "Bivolt"])
Creating a Custom Object and Fields in Zendesk
Once you define the custom object class, you can create it in Zendesk using ZendeskObjectManager. This will automatically create the custom object and its fields in Zendesk.
from mercuryorm.client.zendesk_manager import ZendeskObjectManager
# Create the custom object and fields in Zendesk
manager = ZendeskObjectManager(email="your-email@example.com")
manager.create_custom_object_from_model(Product)
# or
manager.get_or_create_custom_object_from_model(Product)
Record Manager
Each custom object class is automatically assigned a RecordManager that handles interaction with the Zendesk API. The RecordManager allows you to:
- Create records:
Product.objects.create(**kwargs) - Get a single record:
Product.objects.get(id=1) - Filter records:
Product.objects.filter(active=True) - Delete records:
Product.objects.delete(id=1) - Retrieve all records:
Product.objects.all()
Creating a Record
You can create a new record by instantiating your custom object and calling the save() method:
product = Product(name="Sample Product", code="12345", price=99.99, active=True)
product.save()
#or
Product.objects.create(name="Sample Product", code="12345", price=99.99, active=True)
Retrieving a Record
You can retrieve an individual record by using the get() method:
retrieved_product = Product.objects.get(id=product.id)
Updating a Record
To update a record, modify its attributes and call the save() method again:
retrieved_product.price = 89.99
retrieved_product.save()
Deleting a Record
To delete a record from Zendesk, call the delete() method on the object:
retrieved_product.delete()
Querying and Filtering Records
You can retrieve all records or filter them based on certain criteria.
all_products = Product.objects.all()
filtered_products = Product.objects.filter(active=True)
last_object = Product.objects.last()
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 mercury_orm-0.1.0.tar.gz.
File metadata
- Download URL: mercury_orm-0.1.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9ad9e0b95a92ddfe794a5a9e0ffa8d1497f0cddba51fb3da7f7d2ae9980562a
|
|
| MD5 |
1d9f5a6768ecfcbe14b9c4d96a8fbe48
|
|
| BLAKE2b-256 |
00994d25e318778e07382b640bc15d65029e51f467c67b34523c70479da28170
|
File details
Details for the file mercury_orm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mercury_orm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c09047232a0c3c7b1ee7223e77e171609d72ef0e783206e8e586deac5d1f6319
|
|
| MD5 |
230b65721e5488180f201076eeaad8d2
|
|
| BLAKE2b-256 |
2b082bd1fc5a78c1da99ba709d859f4684cfdefcce9baef3e7a97932d6dec1fe
|