Python SDK class for Django to create convenient CRUD and Non CRUD third-party integrations
Project description
🔌 Integrator System
This module provides a lightweight abstraction for integrating external CRUD-based APIs with your Django models. It defines a base Integrator class and a specialized CrudIntegrator class to manage create, update, and delete operations while mapping responses back to local Django models.
📦 Classes Overview
BaseIntegrator
A base class designed to prepare data, configure headers, and validate HTTP responses.
✅ Responsibilities:
Initialize headers, data, and rate_limit attributes.
Provide a validate_response() method that:
Parses the HTTP response JSON.
Logs response success or failure.
Extracts and returns the 'id' from the JSON (or full content fallback).
Convert a model-like object to dictionary using model.dict().
🔧 Methods:
set_headers(): Override to define custom HTTP headers.
set_data(model): Prepares the model payload as a dictionary.
validate_response(response): Handles status code and JSON parsing for HTTP responses.
CrudIntegrator
A subclass of BaseIntegrator that specializes in full CRUD operations for Django models via external APIs.
✅ Responsibilities:
Maps Django model classes to remote API endpoints.
Sends HTTP requests to external systems.
Writes responses back to local Django models (.objects.create(...), etc.).
🧠 Requires:
A defined dictionary of object_types, mapping string keys to:
model: A Django model class
endpoint: A relative API path
A data_constraints structure to restrict invalid payloads (e.g. forbidden values).
🔧 Methods:
create_object(object_id): Sends a POST request to the API. If successful, creates a corresponding object in the local DB.
update_object(object_id: int): Sends a PATCH request to update an existing record, found by object_id.
delete_object(object_id: int): Sends a DELETE request and deletes the local object after remote deletion.
validate_object(): Ensures object_type exists in the object_types mapping.
validate_data(): Enforces value constraints from data_constraints before proceeding with remote API operations.
🧱 Type Definitions
Located in types.py (or definitions.py), used to enforce type safety:
python Copy Edit from typing import Protocol, TypedDict, Type, Any from django.db.models.manager import Manager
class DjangoModelProtocol(Protocol): objects: Manager _meta: Any
class ObjectTypeDefinition(TypedDict): model: Type[DjangoModelProtocol] endpoint: str
🧪 Example Usage
python Copy Edit class ProductModel(models.Model): ...
class MyIntegrator(CrudIntegrator): @staticmethod def set_object_types(): return { "product": { "model": ProductModel, "endpoint": "products" } }
@staticmethod
def set_data_constraints():
return {
"product": {"status": ["invalid", "archived"]}
}
🚨 Notes
This system assumes each remote object has an id returned in its API response.
Make sure your models are compatible with the fields being returned or used.
Designed to be extended and customized per integration.
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 dachintegrator-1.0.0.tar.gz.
File metadata
- Download URL: dachintegrator-1.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efc19ff62e62227a4045bba954d68164773ba223ccc72ed15b56c6f1b4a2d743
|
|
| MD5 |
11e70d24be765cae60c73eb0b2d9a8c7
|
|
| BLAKE2b-256 |
c571758e6978cd34fcd76c598ede388bed504533fe2910e84f46c702614cbc18
|
File details
Details for the file dachintegrator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dachintegrator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acb041e75bc5f2e68a4a42d6d457942ae107fcfb0c06fb672c4b3c5faf1a9bc7
|
|
| MD5 |
37f4493899582112f403c65c663498e2
|
|
| BLAKE2b-256 |
a56173c5e0ff026676c6551b44228f7c6f400ea05630538712ca432f871db1b4
|