Skip to main content

Common utilities, settings, and contracts for Anet Microservices (Django/DRF)

Project description

Anet Common Library

Ushbu kutubxona Anet loyihasining mikroservislari uchun umumiy standartlar, sozlamalar va yordamchi vositalarni (utilities) o'z ichiga oladi.

O'rnatish

pip install anet-common

(Yoki private repodan o'rnatish)

Foydalanish

Mikroservisning settings.py faylida ushbu kutubxonadan standart konfiguratsiyalarni import qiling va ularni kengaytiring (extend).

settings.py namunasi:

from anet_common.conf import (
    COMMON_LANGUAGES, 
    COMMON_MODELTRANSLATION_LANGUAGES,
    COMMON_REST_FRAMEWORK,
    COMMON_SPECTACULAR_SETTINGS
)

# 1. MIDDLEWARE
MIDDLEWARE = [
    "anet_common.middleware.RequestIdMiddleware", # Eng yuqorida tursin
    "django.middleware.locale.LocaleMiddleware",
    # ... boshqa middlewarelar
]

# 2. TILLAR VA VAQT
TIME_ZONE = "Asia/Tashkent"
LANGUAGE_CODE = "uz"
LANGUAGES = COMMON_LANGUAGES 
# Natija: (('uz', "O'zbek"), ('ru', "Русский"), ('en', "English"))

MODELTRANSLATION_LANGUAGES = COMMON_MODELTRANSLATION_LANGUAGES
MODELTRANSLATION_DEFAULT_LANGUAGE = "uz"

# 3. DRF SOZLAMALARI
REST_FRAMEWORK = COMMON_REST_FRAMEWORK.copy()
REST_FRAMEWORK.update({
    # Loyihaga xos qo'shimchalar
    "DEFAULT_PERMISSION_CLASSES": (
        "rest_framework.permissions.IsAuthenticated",
    ),
})

# 4. SPECTACULAR (SWAGGER) SOZLAMALARI
SPECTACULAR_SETTINGS = COMMON_SPECTACULAR_SETTINGS.copy()
SPECTACULAR_SETTINGS.update({
    "TITLE": "Mening Mikroservis API",
    "DESCRIPTION": "Bu servis faqat ... uchun javob beradi",
    "VERSION": "1.0.0",
})

# 5. SERVIS MA'LUMOTLARI (Meta uchun)
SERVICE_NAME = "my-service"
SERVICE_VERSION = "v1"

Tarkibi va Konstantalar

1. COMMON_LANGUAGES

Loyiha qo'llab quvvatlaydigan 3 ta asosiy til:

  • uz: O'zbek
  • ru: Rus
  • en: Ingliz

2. COMMON_REST_FRAMEWORK

Quyidagi standart sozlamalarni o'z ichiga oladi:

  • Renderer: anet_common.drf.renderers.AnetJSONRenderer. Bu javoblarni standart formatga o'tkazadi.
  • Parser: CamelCaseJSONParser va standart parserlar.
  • Exception Handler: anet_common.drf.exceptions.custom_exception_handler. Bu handler barcha xatolarni katalogdan olib, yagona formatga o'tkazadi.
  • Pagination: StandardPageNumberPagination (default page_size=20).

3. Response Formati

Ushbu kutubxona ishlatilganda, API javoblari quyidagi standart formatlarda qaytadi:

A. Success - List (Pagination bilan)

{
  "success": true,
  "data": [
    {"id": 1, "name": "Acme LLC"},
    {"id": 2, "name": "Beta LLC"}
  ],
  "errors": [],
  "meta": {
    "request_id": "req-123",
    "timestamp": "2026-01-21T10:15:30Z",
    "service": "company-service",
    "version": "v1",
    "language": "uz",
    "pagination": {
      "page": 1,
      "page_size": 20,
      "total_items": 120,
      "total_pages": 6,
      "has_next": true,
      "has_prev": false
    }
  }
}

B. Success - Detail (Single Object)

{
  "success": true,
  "data": {
    "id": 1,
    "name": "Acme LLC"
  },
  "errors": [],
  "meta": {
    "request_id": "req-123",
    "timestamp": "2026-01-21T10:15:30Z",
    "service": "company-service",
    "version": "v1",
    "language": "uz"
  }
}

C. Error Response

Xatoliklar har doim errors ro'yxati ichida qaytadi. data null bo'ladi.

{
  "success": false,
  "data": null,
  "errors": [
    {
      "code": "VAL-0001",
      "message": "Topilmadi", 
      "detail_message": "No BookingItem matches the given query.",
      "field": "email",
      "source": null,
      "details": null
    }
  ],
  "meta": {
    "request_id": "req-123",
    "timestamp": "2026-01-21T10:15:30Z",
    "service": "auth-service",
    "version": "v1",
    "language": "uz"
  }
}

Xatoliklar Katalogi

Xatoliklar markazlashgan JSON katalogi orqali boshqariladi. Yangi xatolik qo'shish uchun kutubxona yangilanishi kerak.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anet_common-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anet_common-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file anet_common-0.1.1.tar.gz.

File metadata

  • Download URL: anet_common-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for anet_common-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a144d88279f1eb78047031f576256ed42c47a8b808d2fdf12a163afa87eaf6b1
MD5 56c901e058aca79d0e7fe576888ddbcd
BLAKE2b-256 7d1b185adb82f646474876060e47afbca8c49d46ad4c1b5e1a6845a8d8c224bd

See more details on using hashes here.

File details

Details for the file anet_common-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: anet_common-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for anet_common-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bda22f55fc6c0d0f7afaf16aaa8efac8e9615bd571fbea97a7d6cf063bd0f4b2
MD5 78f19e83c19288e1dea416d69297a9e8
BLAKE2b-256 6f461a15b4c2386fc790dee78eeeeae2e837cbcf9c81c2f3fe602fddbe0598ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page