Skip to main content

Library for separating data input, output and processing in your business application.

Project description

Mario

Build Status Maintainability Test Coverage

Library for separating data input, output and processing in your business application.

Mario

Disclaimer: the library is sooo pre-alpha.

Usage example

class VisitHistoryView(BasePipeline):
    pipeline = [
        'get_user_bills',
        'get_user_legals',
        'calculate_visits_periods',
        'format_json_response',
    ]

    @input_pipe
    def get_user_bills(user: User) -> List[UserBill]:  # User and UserBill is a Python dataclass
        """
        Returns list of python dataclasses, that represents information about user bills.
        
        - no business logic on this layer (use linters for detect high complexity level)
        - we can use database access on this layer, but only through special context manager 
        - here we have special model manager that returns simple dataclass, not an orm instance
        - we take `user` arguments from base context, that was filled by PipelineView
        - we have no access to base context from any method
        """
        return UserBill.objects_to_dataclass.get_user_bills(user)

    @process_pipe
    def calculate_visits_periods(user_bills: List[UserBill]) -> List[VisitsPeriods]:
        """
        VisitsPeriods is a business logic hadler.
        
        - we can't use database access on this layer
        - it's a domain entity
        - it has no ability to interact with external dependencies
        - when we change something in outer world, we should not make any change in this layer
        - also, we should have here the best code. This code should be tested very well
        """
        return VisitsPeriods.calculate(patient_bills)

    @output_pipe
    def get_pipeline_result(visits_periods: List[VisitsPeriodsDataClass]) -> JsonResponse:
        """
        Representation layer.
    
        - we can use database access on this layer, but only through special context manager
        - it also takes dataclasses
        - no business logic on this layer (use linters for detect high complexity level)
        """
        return {'visit_periods': visits_periods}

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

super_mario-0.0.1.tar.gz (3.6 kB view hashes)

Uploaded source

Supported by

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