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.0.tar.gz (3.2 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.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hiten_apicore-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 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.0.tar.gz
Algorithm Hash digest
SHA256 fbc8b3ce0cbb43c6109326035933640668f3e32004233e11bf4569f53e0ca44d
MD5 78fc684281c8dec1e979283d42aeaf05
BLAKE2b-256 9b3fc29cb1ae1938f4e821a04052dd8a6762ac9b5bf29555fa3a5fc8625aea2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hiten_apicore-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bf9dd7da4e0e6ab227db2be7a2d9ffcc04711eeb1b5b0785dcfb41f396deba6
MD5 d0bd9542a39fb8a4dc7b81619d1c95e2
BLAKE2b-256 441b7608257a06f9de2a2536ed263723161bb6b376660acc8431d2cb39c77bc7

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