{"library":"nsj-rest-lib","title":"NSJ Rest Lib","description":"nsj-rest-lib is a Python library for building declarative REST APIs, adhering to internal guidelines and focusing on DTO (Data Transfer Object) and Entity patterns. It simplifies API creation by abstracting common patterns for data mapping, validation, and persistence. The current version is 6.4.1, and it maintains an active release cadence with regular feature additions and bug fixes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install nsj-rest-lib"],"cli":null},"imports":["from nsj_rest_lib.dto.dto_base import DTOBase","from nsj_rest_lib.dto.fields import DTOField","from nsj_rest_lib.dto.fields import DTOAggregator","from nsj_rest_lib.dto.fields import DTOSQLJoinField","from nsj_rest_lib.entity.entity_base import EntityBase","from nsj_rest_lib.service.service_base import ServiceBase"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from dataclasses import dataclass\nfrom nsj_rest_lib.dto.dto_base import DTOBase\nfrom nsj_rest_lib.dto.fields import DTOField, DTOAggregator\nfrom nsj_rest_lib.entity.entity_base import EntityBase\n\n# 1. Define your Entity (maps to a database table)\n@dataclass\nclass ProductEntity(EntityBase):\n    id: int\n    name: str\n    description: str\n    price: float\n\n# 2. Define your DTO (Data Transfer Object, maps to API representation)\nclass ProductDTO(DTOBase):\n    id: int = DTOField(pk=True)\n    name: str = DTOField()\n    price: float = DTOField(decimal_places=2)\n\n# 3. Example of an aggregated DTO using DTOAggregator (v4.9.0+)\nclass ProductDetailsDTO(DTOBase):\n    category: str = DTOField()\n    weight_kg: float = DTOField()\n\nclass FullProductDTO(DTOBase):\n    id: int = DTOField(pk=True)\n    name: str = DTOField()\n    description: str = DTOField()\n    details: ProductDetailsDTO = DTOAggregator()\n\nprint(\"DTOs and Entities defined successfully.\")\nprint(f\"ProductDTO fields: {ProductDTO.get_fields()}\")\nprint(f\"FullProductDTO fields: {FullProductDTO.get_fields()}\")\n","lang":"python","description":"This quickstart demonstrates how to define an Entity (mapping to a database table) and various DTOs (Data Transfer Objects) for API representation, including using `DTOAggregator` for nested structures that map to a single underlying entity. This setup forms the core declarative definition for building REST APIs with nsj-rest-lib.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}