Skip to main content

Classic App Layer

This package provides primitives for application layer. Part of project "Classic".

Usage for validation:

from dataclasses import dataclass

from classic.app import DTO, validate_with_dto
from pydantic import validate_arguments


class SomeDTO(DTO):
    """Based on pydantic.BaseModel. Used for validating input"""
    
    some_field: int
    another_field: str


@dataclass
class SomeAppCls:
    """Some class with app logic. May be mapped on DB."""
    some_field: int
    another_field: str


class SomeService:
    
    @validate_arguments
    def some_method(self, arg: int):
        assert isinstance(arg, int)
    
    @validate_with_dto
    def another_method(self, params: SomeDTO):
        instance = params.create_obj(SomeAppCls)
        print(instance)

Usage for errors:

from classic.app import AppError, ErrorsList


# Describe errors, possible in application
class IncorrectState(AppError):
    msg_template = 'Incorrect app state - "{text}"'
    code = 'app.incorrect_state'


class ServiceNotReady(AppError):
    msg_template = 'Service not ready yet'
    code = 'app.service_not_ready'


# In another file with services:
class SomeService:
    
    def __init__(self):
        self.ready_to_serve = False

    def is_ready(self):
        """Demonstrates simple usage"""
        if not self.ready_to_serve:
            raise ServiceNotReady()

    def mark_as_ready(self):
        """Demonstrates usage of error message templates"""
        if self.ready_to_serve:
            raise IncorrectState(text='Service are ready')
        self.ready_to_serve = True

    def just_give_errors(self):
        """Demonstrates method, what may have more than 1 error"""
        errors = [IncorrectState(text='error 1'), 
                  IncorrectState(text='error 2')]
        raise ErrorsList(errors)


# Somewhere in adapters:

service = SomeService()

try:
    service.is_ready()
except AppError as error:
    print(f'Application responses with error code "{error.code}", '
          f'message is "{error.message}"')

try:
    service.mark_as_ready()
    service.mark_as_ready()
except AppError as error:
    print(f'Application responses with error code "{error.code}", '
          f'message is "{error.message}"')
    
try:
    service.just_give_errors()
except ErrorsList as errors_list:
    for error in errors_list.errors:
        print(f'Application responses with error code "{error.code}", '
              f'message is "{error.message}"')

Metadata

Release files for classic-app-layer 0.0.1

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

Source distribution (sdist)

Source distribution for classic-app-layer 0.0.1
File Size Uploaded Provenance
classic-app-layer-0.0.1.tar.gz 4.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for classic-app-layer 0.0.1
File Interpreter ABI Platform
classic_app_layer-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / classic-app-layer-0.0.1.tar.gz

Download URL classic-app-layer-0.0.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2a2ff4a0654221cd94b1b24842027887a07a08b096ac0f3fb3d55dafdef2e1d4
BLAKE2b-256 checksum
How to use checksums
f920e3166334a5bb89a13ca789020eeb2a005d15b6a9a68c51475fa0bc2759ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

Release files / classic_app_layer-0.0.1-py3-none-any.whl

Download URL classic_app_layer-0.0.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ab8f8b39627df7d9ad17b1770672f0ddbdf4b792a17b89ec0c897743bbc715e
BLAKE2b-256 checksum
How to use checksums
86d0c94f5b0deaf1a8146bb846949b7301bc1c041c96494918112826c5040caf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

Security for classic-app-layer 0.0.1

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

0.0.1 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