Skip to main content

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

  • integration AppConfig that validates required INSTALLED_APPS and MIDDLEWARE
  • firebase helper to initialize firebase-admin using FIREBASE_AUTHENTICATION setting
  • integration.serializers.BaseModelSerializer with json_fields support 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: installs firebase-admin (use pip install idtinc[firebase])

Installation

Install from PyPI:

pip install idtinc
# or with firebase support
pip install idtinc[firebase]

Quickstart

  1. Add the package to INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
    # ...
    "idtinc.integration",
    # optionally
    "idtinc.firebase",
]
  1. 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",
]
  1. (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.

  1. 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 for firebase-admin credentials (required when using idtinc.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.

  1. 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"
  1. 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

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?

Metadata

Release files for idtinc 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for idtinc 1.0.0
File Size Uploaded Provenance
idtinc-1.0.0.tar.gz 37.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for idtinc 1.0.0
File Interpreter ABI Platform
idtinc-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.7 kB

Release files / idtinc-1.0.0.tar.gz

Download URL idtinc-1.0.0.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9efb0877d68f899fc5a717e05d9779d0044f622af519fc207b97d20fe6c3ee56
BLAKE2b-256 checksum
How to use checksums
b99eb2951f94a4d4725a107ce6c6eeedfaaede1fb4e19084439185ce96034843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / idtinc-1.0.0-py3-none-any.whl

Download URL idtinc-1.0.0-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
696acb79e56776c28d679c7cf2466651edc6b978773934ef343bcc60687715be
BLAKE2b-256 checksum
How to use checksums
d58902e4c29c62151cc94f9e196bf4f875c5d004362caf1c7ec45619a8f185cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for idtinc 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page