Idtinc Django & DRF Library
Project description
idtinc
Idtinc is a small utility library for Django + Django REST Framework that provides:
- Reusable DRF serializers and custom fields (choice helpers, coordinates, BaseModelSerializer)
- Integration helpers and app configs to warn about required middleware/apps
- Optional Firebase initialization helper and AppConfig
- Query helpers for Postgres JSON, unaccent, json_agg, and storage URL helpers
- Message constants in Vietnamese for consistent API responses
This package is intended for Django projects that need common patterns and helpers extracted into a reusable library.
Features
integrationAppConfig that validates required INSTALLED_APPS and MIDDLEWAREfirebasehelper to initializefirebase-adminusingFIREBASE_AUTHENTICATIONsettingintegration.serializers.BaseModelSerializerwithjson_fieldssupport and nicer form-data handling- Query helpers:
SubqueryJson,SubqueryJsonAgg,UnaccentVN,json_build_object, etc. - Storage helpers that call Django's
default_storage(works with MinIO/backblaze backends)
Requirements
- Python >= 3.9
- Django >= 3.2
- djangorestframework >= 3.14
Core dependencies are declared in pyproject.toml.
Optional extras:
firebase: installsfirebase-admin(usepip install idtinc[firebase])
Installation
Install from PyPI:
pip install idtinc
# or with firebase support
pip install idtinc[firebase]
Quickstart
- Add the package to
INSTALLED_APPSin your Django settings:
INSTALLED_APPS = [
# ...
"idtinc.integration",
# optionally
"idtinc.firebase",
]
- Ensure the recommended middleware are present (or you will get a runtime warning from the AppConfig):
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
# ...
"django_currentuser.middleware.ThreadLocalUserMiddleware",
"idtinc.integration.middleware.CustomLocaleMiddleware",
"idtinc.integration.middleware.ExceptionMiddleware",
]
- (Optional) Firebase initialization
Set FIREBASE_AUTHENTICATION in settings to the credentials object or path required by firebase-admin:
# Example (path to service account JSON file):
FIREBASE_AUTHENTICATION = {
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url": "",
"universe_domain": "",
}
When idtinc.firebase AppConfig becomes ready it will call the helper that initializes the Firebase app.
- Setup logging
from idtinc.integration.logging import get_setup_logging
LOGGING = get_setup_logging()
Usage examples
- BaseModelSerializer (handles form-data JSON fields):
from idtinc.integration.serializers import BaseModelSerializer
class MySerializer(BaseModelSerializer):
class Meta:
model = MyModel
fields = "__all__"
json_fields = ("metadata",)
- Choice fields that output label/value pairs:
from idtinc.integration.serializers import ChoiceField
class ItemSerializer(serializers.ModelSerializer):
status = ChoiceField(choices=MyModel.STATUS_CHOICES)
class Meta:
model = MyModel
fields = ("id", "status")
- Firebase helper (manual use):
from idtinc.firebase.initialize import firebase_config
firebase_app = firebase_config()
Configuration
Key settings used by the library:
FIREBASE_AUTHENTICATION— dict forfirebase-admincredentials (required when usingidtinc.firebase)
The integration AppConfig will warn about missing apps/middleware but does not modify your settings automatically.
Storage backends
The library uses Django's default_storage for generating storage URLs so you can plug in MinIO, Backblaze, or any Django storage backend. Example storage backends are provided under src/idtinc/storage.
- MinIO Storage
Django Storage backend for MinIO.
Reads configuration from Django settings when not provided explicitly:
- STORAGE_MINIO_ENDPOINT
- STORAGE_MINIO_ACCESS_KEY
- STORAGE_MINIO_SECRET_KEY
- STORAGE_MINIO_SECURE
- STORAGE_MINIO_BUCKET_NAME
# For Django 4.2+
STORAGES = {
"default": {
"BACKEND": "django_library.core.files.storage.MinioStorage",
},
}
# Or with options
STORAGES = {
"default": {
"BACKEND": "django_library.core.files.storage.MinioStorage",
"OPTIONS": {
"bucket_name": "",
"endpoint": "", # s3.example.com
"access_key": "",
"secret_key": "",
"secure": True, # True or False
},
},
}
# For Django versions below 4.2
DEFAULT_FILE_STORAGE = "django_library.core.files.storage.MinioStorage"
- Backblaze B2 Storage
# Django Storage backend for Backblaze B2.
Reads configuration from Django settings when not provided explicitly:
STORAGE_BACKBLAZE_APP_KEY
STORAGE_BACKBLAZE_ACCOUNT_ID
STORAGE_BACKBLAZE_BUCKET_NAME
STORAGE_BACKBLAZE_BUCKET_ID
# For Django 4.2+
STORAGES = {
"default": {
"BACKEND": "django_library.core.files.storage.BackblazeStorage",
},
}
# Or with options
STORAGES = {
"default": {
"BACKEND": "django_library.core.files.storage.BackblazeStorage",
"OPTIONS": {
"app_key": "",
"account_id": "",
"bucket_name": "",
"bucket_id": "",
},
},
}
# For Django versions below 4.2
DEFAULT_FILE_STORAGE = "django_library.core.files.storage.BackblazeStorage"
Development
Run tests and linters (if present) in your local environment. See pyproject.toml for package metadata.
License & Author
- Author: Kiều Văn Chương vanchuongkieu@gmail.com
- License: MIT
Contributing
Issues and pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
If you'd like, I can also add short code examples for middleware usage, or generate a minimal example Django project showing integration. Which would you prefer next?
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 idtinc-1.0.0.tar.gz.
File metadata
- Download URL: idtinc-1.0.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9efb0877d68f899fc5a717e05d9779d0044f622af519fc207b97d20fe6c3ee56
|
|
| MD5 |
0465dbfb9dd9c4984c5beb2086677e93
|
|
| BLAKE2b-256 |
b99eb2951f94a4d4725a107ce6c6eeedfaaede1fb4e19084439185ce96034843
|
File details
Details for the file idtinc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: idtinc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 45.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
696acb79e56776c28d679c7cf2466651edc6b978773934ef343bcc60687715be
|
|
| MD5 |
cff09e6220076134f3935da18ffd1b6a
|
|
| BLAKE2b-256 |
d58902e4c29c62151cc94f9e196bf4f875c5d004362caf1c7ec45619a8f185cd
|