Skip to main content

Lightweight API infrastructure toolkit for standardized responses, errors, and retry handling.

Project description

Apicore

Lightweight API infrastructure toolkit for Django REST Framework providing standardized responses, errors, permissions, and CRUD operations.

Features

  • BaseModel with timestamps and soft delete
  • Standardized API responses
  • Custom exception classes
  • Permission classes (IsOwner, IsActiveUser, ReadOnly)
  • BaseViewSet with CRUD operations
  • Pagination with metadata
  • Request tracing decorator
  • Common constants

Installation

pip install apicore

Usage

BaseModel

from apicore import BaseModel

class Product(BaseModel):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2)

BaseViewSet

from apicore import BaseViewSet, StandardPagination
from rest_framework.permissions import IsAuthenticated

class ProductViewSet(BaseViewSet):
    queryset = Product.objects.all()
    serializer_class = ProductSerializer
    permission_classes = [IsAuthenticated]
    pagination_class = StandardPagination

Permissions

from apicore import IsOwner, IsActiveUser, ReadOnly

class MyViewSet(BaseViewSet):
    permission_classes = [IsActiveUser, IsOwner]

Error Handling

from apicore import NotFoundError, ValidationError

def my_view(request):
    if not obj:
        raise NotFoundError("Product not found")
    if not valid:
        raise ValidationError("Invalid data", errors={"field": "error"})

Request Tracing

from apicore import trace_request

class MyViewSet(BaseViewSet):
    @trace_request
    def list(self, request, *args, **kwargs):
        return super().list(request, *args, **kwargs)

Response Format

Success:

{
    "status": "success",
    "data": {...},
    "message": "Operation successful",
    "meta": {...}
}

Error:

{
    "status": "error",
    "message": "Error message",
    "error_code": "ERROR_CODE",
    "errors": {...}
}

License

MIT

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

hiten_apicore-0.1.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

hiten_apicore-0.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hiten_apicore-0.1.1.tar.gz
Algorithm Hash digest
SHA256 66855f2cfdc8a4cfefc4f21f7b366d5bfcf3b92443d6ad2d56543e968ee08e5c
MD5 fa8f031de56669b54980111cfbb48bcb
BLAKE2b-256 f27744379fd632892f36cf613c82b28876efd48a411779e38f63e770752283a0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hiten_apicore-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e411b9b782b89b1716b482c977fa2e705f98d496e4f14aa17ec950e50fb1d3d
MD5 b40d0f1065b6f93214fb4345367f37b4
BLAKE2b-256 38f4f11ba03773d54f020d1089f00ed99f463cdc05773ce34983e313e2952092

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