Skip to main content

Sincpro framework to use DDD, Clean architecture, Hexagonal architecture

Project description

๐Ÿš€ Sincpro Framework: Application Layer Framework within Hexagonal Architecture

โšก Quick Start

Here's a quick example to get you started with the Sincpro Framework:

๐Ÿ Quick Example

from sincpro_framework import UseFramework, Feature, DataTransferObject

# 1. Initialize the framework
framework = UseFramework("cybersource")

# 2. Add Dependencies (Example dependencies)
from sincpro_framework import Database

db = Database()
framework.add_dependency("db", db)

# 3. Error Handler (Optional, use the built-in error handling feature)
framework.set_global_error_handler(lambda e: print(f"Error: {e}"))


# 4. Create a Use Case with DTOs
class GreetingParams(DataTransferObject):
    name: str


@framework.feature(GreetingParams)
class GreetingFeature(Feature):
    def execute(self, dto: GreetingParams) -> str:
        self.db.store(f"Greeting {dto.name}")
        return f"Hello, {dto.name}!"


# 5. Execute the Use Case
if __name__ == "__main__":
    # Create an instance of the parameter DTO
    greeting_dto = GreetingParams(name="Alice")
    # Execute the feature
    result = framework(greeting_dto)
    print(result)  # Output: Hello, Alice!

Now you are ready to explore more complex use cases! ๐Ÿš€

๐Ÿ“‘ Table of Contents

  1. Overview of Hexagonal Architecture
  2. Key Features of the Sincpro Framework
  3. Features vs. Application Service
  4. Example Usage for a Payment Gateway
  5. Creating a Feature
  6. Creating an Application Service
  7. Executing a Use Case
  8. Summary
  9. Configuration or settings
  10. Variables

๐Ÿ” Overview of Hexagonal Architecture

Hexagonal Architecture, also known as Ports and Adapters, is an architectural approach that aims to decouple core business logic from external dependencies. It organizes the system into distinct layers: domain, application, and infrastructure, enhancing maintainability, scalability, and adaptability.

๐Ÿ—๏ธ Key Layers of Hexagonal Architecture

  • Core Domain: This layer encapsulates essential entities, value objects, and domain services representing the core business rules and behaviors. It is kept strictly independent from infrastructure concerns, preserving business logic integrity.
  • Application Layer: Orchestrates user requests, processes domain responses, and mediates interactions between domain and external systems to ensure effective workflow execution.
  • Infrastructure Layer: Contains adapters for interacting with databases, APIs, messaging systems, and other services. It handles data transformation to ensure compatibility with the domain and application layers.

๐Ÿค” Why Use a Unified Bus Pattern?

The Sincpro Framework adopts a unified bus pattern as a single point of entry for managing use cases, dependencies, and services within a bounded context. This simplifies the architecture by encapsulating all requirements of a given context, ensuring a clear and consistent structure.

Using a unified bus allows developers to access all dependencies through a single environment, eliminating the need for repeated imports or initialization. This approach ensures each bounded context is self-sufficient, independently scalable, and minimizes coupling while enhancing modularity.

๐Ÿ”‘ Key Features of the Sincpro Framework

The Sincpro Framework follows hexagonal architecture principles, promoting modularity, scalability, and development efficiency. Here are its core features:

โœ… DTO Validation with Pydantic

  • Utilizes Pydantic to validate Data Transfer Objects (DTOs).
  • Ensures only well-structured data is allowed into core business logic, reducing errors and maintaining data integrity.

๐Ÿงฉ Dependency Injection

  • Facilitates integration of user-defined dependencies, promoting modular design.
  • Enhances unit testing by allowing easy mocking or replacement of dependencies.

๐Ÿ”„ Inversion of Control (IoC)

  • Automates the instantiation and configuration of components, reducing boilerplate code.
  • Encourages loose coupling, making systems more adaptable and maintainable.

๐Ÿ“ก Context Manager for Metadata Propagation

  • Provides automatic metadata propagation across Features and ApplicationServices without manual parameter passing.
  • Uses Python's contextvars for thread-safe context storage and isolation.
  • Supports nested contexts with override capabilities for complex workflows.
  • Enriches exceptions with context information for better debugging and observability.
# Simple context usage
with app.context({"correlation_id": "123", "user.id": "admin"}) as app_with_context:
    result = app_with_context(some_dto)  # Context automatically available in handlers

# Nested contexts with overrides
with app.context({"env": "prod", "user": "admin"}) as outer_app:
    with outer_app.context({"env": "staging"}) as inner_app:  # Override env, inherit user
        inner_app(dto)  # env="staging", user="admin"

# Access context in Features and ApplicationServices
class PaymentFeature(Feature):
    def execute(self, dto: PaymentDTO) -> PaymentResponse:
        correlation_id = self.context.get("correlation_id")
        user_id = self.context.get("user.id")
        # Use context in business logic...

โš ๏ธ Error Handling at Different Levels

  • Provides centralized error handling at multiple levels: global, Service Application, and Feature levels.
  • Ensures consistent error management, improving overall reliability.

๐ŸšŒ Bus Pattern for Component Communication

  • Implements a bus mechanism to facilitate communication between Feature and ApplicationService components.
  • Decouples component interactions, resulting in more flexible and scalable business logic.

๐Ÿงฉ Decoupled Logic Execution

  • Supports independent execution of use cases through the Feature component, promoting separation of concerns.
  • For example, a user registration workflow can be broken down into steps like input validation, profile creation, and email notification.

๐ŸŽป Application Service Orchestration

  • Uses a feature bus to orchestrate multiple features into complex business workflows (e.g., customer onboarding).
  • Integrates smaller use cases into cohesive flows to manage entire business processes effectively.

๐Ÿ’ป IDE Support with Typing

  • Uses type hints to enhance code quality and support features like autocompletion and type checking.
  • Improves development efficiency and reliability.

โš™๏ธ Features vs. Application Service

  • Feature: Represents a discrete, self-contained use case focused on specific functionality, easy to develop and maintain.
  • ApplicationService: Orchestrates multiple features for broader business objectives, providing reusable components and workflows.

๐Ÿ’ณ Example Usage for a Payment Gateway

The following example shows how to configure the Sincpro Framework for a payment gateway integration, such as CyberSource. It is recommended to name the framework instance to clearly represent the bounded context it serves.

๐Ÿ”ง Configuring the Framework

To set up the Sincpro Framework, configuration should be performed at the application layer within the use_cases directory of each bounded context.

sincpro_payments_sdk/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ cybersource/
โ”‚   โ”‚   โ”œโ”€โ”€ adapters/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ cybersource_rest_api_adapter.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ domain/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ card.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ customer.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ infrastructure/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ logger.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ aws_services.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ orm.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚   โ””โ”€โ”€ use_cases/
โ”‚   โ”‚       โ”œโ”€โ”€ tokenization/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ new_tokenization_feature.py
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚       โ”œโ”€โ”€ payments/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ token_and_payment_service.py
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”‚       โ””โ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ qr/
โ”‚   โ”œโ”€โ”€ sms_payment/
โ”‚   โ”œโ”€โ”€ bank_api/
โ”‚   โ”œโ”€โ”€ online_payment_gateway/
โ”‚   โ””โ”€โ”€ paypal_integration/
โ””โ”€โ”€ tests

๐Ÿ“‹ Best Practices for Imports

Each use case should import both the DTO for input parameters and the DTO for responses to maintain clarity and consistency.

๐Ÿ“ Sample Configuration in __init__.py

from typing import Type

from sincpro_framework import Feature as _Feature
from sincpro_framework import UseFramework as _UseFramework
from sincpro_framework import ApplicationService as _ApplicationService

from sincpro_payments_sdk.apps.cybersource.adapters.cybersource_rest_api_adapter import (
    ESupportedCardType,
    TokenizationAdapter,
)
from sincpro_payments_sdk.infrastructure.orm import with_transaction as db_session
from sincpro_payments_sdk.infrastructure.aws_services import AwsService as aws_service

# Create an instance of the framework
cybersource = _UseFramework()

# Register dependencies
cybersource.add_dependency("token_adapter", TokenizationAdapter())
cybersource.add_dependency("ECardType", ESupportedCardType)
cybersource.add_dependency("db_session", db_session)
cybersource.add_dependency("aws_service", aws_service)


# Define a custom Feature class to access the dependencies
class Feature(_Feature):
    token_adapter: TokenizationAdapter
    ECardType: Type[ESupportedCardType]
    db_session: ...
    aws_service: ...
    logger: ...


# Define a custom Application Service class to access dependencies
class ApplicationService(_ApplicationService):
    token_adapter: TokenizationAdapter
    ECardType: Type[ESupportedCardType]
    db_session: ...
    aws_service: ...
    logger: ...
    feature_bus: ...


# Add use cases (Application Services and Features)
from . import tokenization

__all__ = ["cybersource", "tokenization", "Feature"]

๐Ÿ› ๏ธ Creating a Feature

To create a new Feature, follow these steps:

  1. Create a Module for the Feature: Add a new Python file in the appropriate folder under use_cases.
  2. Import the Framework and Required Classes: Import the configured framework instance and DataTransferObject.
  3. Define the Parameter and Response DTOs: Use DataTransferObject to create classes for input parameters and responses.
  4. Create the Feature Class: Define the Feature class by inheriting from the custom Feature class.

๐Ÿ–‹๏ธ Example of Creating a Feature

from sincpro_payments_sdk.apps.cybersource import cybersource, DataTransferObject, Feature


# Define parameter DTO
class TokenizationParams(DataTransferObject):
    card_number: str
    expiration_date: str
    cardholder_name: str


# Define response DTO
class TokenizationResponse(DataTransferObject):
    token: str
    status: str


# Create the Feature class
@cybersource.feature(TokenizationParams)
class NewTokenizationFeature(Feature):
    def execute(self, dto: TokenizationParams) -> TokenizationResponse:
        # Example usage of dependencies
        cybersource.logger.info("Starting tokenization process")
        token = self.token_adapter.create_token(
            card_number=dto.card_number,
            expiration_date=dto.expiration_date,
            cardholder_name=dto.cardholder_name
        )
        return TokenizationResponse(token=token, status="success")

๐Ÿ”„ Creating an Application Service

ApplicationService is used to coordinate multiple features while maintaining reusability and consistency. It orchestrates features into cohesive workflows.

๐Ÿ’ก Example of Creating an Application Service

from sincpro_payments_sdk.apps.cybersource import cybersource, DataTransferObject, ApplicationService
from sincpro_payments_sdk.apps.cybersource.use_cases.tokenization import TokenizationParams


# Define parameter DTO
class PaymentServiceParams(DataTransferObject):
    card_number: str
    expiration_date: str
    cardholder_name: str
    amount: float


# Define response DTO
class PaymentServiceResponse(DataTransferObject):
    status: str
    transaction_id: str


# Create the Application Service class
@cybersource.app_service(PaymentServiceParams)
class PaymentOrchestrationService(ApplicationService):
    def execute(self, dto: PaymentServiceParams) -> PaymentServiceResponse:
        # Create the command DTO for tokenization
        tokenization_command = TokenizationParams(
            card_number=dto.card_number,
            expiration_date=dto.expiration_date,
            cardholder_name=dto.cardholder_name
        )
        tokenization_result = self.feature_bus.execute(tokenization_command)

        # Example usage of dependencies
        cybersource.logger.info("Proceeding with payment after tokenization")
        # Proceed with payment using the token (pseudo code for payment processing)
        transaction_id = "12345"  # Simulated transaction ID
        return PaymentServiceResponse(status="success", transaction_id=transaction_id)

โš™๏ธ Executing a Use Case

Once a Feature or ApplicationService is defined, it can be executed by passing the appropriate DTO instance.

๐Ÿ“Œ Example of Executing a Use Case

from sincpro_payments_sdk.apps.cybersource import cybersource
from sincpro_payments_sdk.apps.cybersource.use_cases.tokenization import TokenizationParams, TokenizationResponse
from sincpro_payments_sdk.apps.cybersource.use_cases.payments import PaymentServiceParams, PaymentServiceResponse

# Example of executing a Feature
feature_dto = TokenizationParams(
    card_number="4111111111111111",
    expiration_date="12/25",
    cardholder_name="John Doe"
)

# Execute the feature
feature_result = cybersource(feature_dto, TokenizationResponse)
print(f"Tokenization Result: {feature_result.token}, Status: {feature_result.status}")

# Example of executing an Application Service
service_dto = PaymentServiceParams(
    card_number="4111111111111111",
    expiration_date="12/25",
    cardholder_name="John Doe",
    amount=100.00
)

# Execute the application service
service_result = cybersource(service_dto, PaymentServiceResponse)
print(f"Payment Status: {service_result.status}, Transaction ID: {service_result.transaction_id}")

๐Ÿ“š Summary

The Sincpro Framework provides a robust solution for managing the application layer within a hexagonal architecture. By focusing on decoupling business logic from external dependencies, the framework promotes modularity, scalability, and maintainability.

  • Features: Handle specific, self-contained business actions.
  • ApplicationServices: Orchestrate multiple features for cohesive workflows.

This structured approach ensures high-quality, maintainable software that can adapt to evolving business needs. ๐Ÿš€

๐Ÿ“– Auto-Documentation

The Sincpro Framework includes a powerful auto-documentation feature that automatically generates comprehensive documentation for your framework instances. This documentation includes all your DTOs, Features, Application Services, Dependencies, and Middlewares in multiple formats optimized for different use cases.

๐Ÿš€ Quick Documentation Generation

The easiest way to generate documentation for your project:

from sincpro_framework.generate_documentation import build_documentation

# Import your framework instances from their respective modules
from apps.payment_gateway import payment_framework
from apps.user_management import user_framework

# Generate traditional markdown documentation (default)
build_documentation(
    [payment_framework, user_framework],
    output_dir="docs/generated"
)

# Generate AI-optimized JSON schema
build_documentation(
    [payment_framework, user_framework],
    output_dir="docs/generated",
    format="json"
)

# Generate chunked JSON for optimal AI consumption (NEW!)
build_documentation(
    [payment_framework, user_framework],
    output_dir="docs/generated",
    format="json",
    chunked=True
)

# Generate both formats
build_documentation(
    [payment_framework, user_framework],
    output_dir="docs/generated", 
    format="both"
)

๐Ÿ“‹ Output Formats

๐Ÿ“ Markdown Documentation (Traditional)

  • MkDocs-ready: Complete documentation website with search
  • Human-readable: Beautiful, professional documentation for developers
  • Interactive: Searchable content with cross-references

๐Ÿค– AI-Optimized JSON Schema (Enhanced!)

  • Complete AI Understanding: Combines framework context with repository analysis
  • Framework Context: How to use the Sincpro Framework (patterns, examples, best practices)
  • Repository Analysis: What components exist in your specific codebase
  • Rich Metadata: Business domains, complexity analysis, architectural patterns
  • Code Generation: Comprehensive hints for AI-powered code generation
  • Embedding Support: Optimized for semantic search and AI embeddings
  • Usage Synthesis: Real examples combining framework knowledge with repository components

๐Ÿ”ฅ NEW: Chunked JSON for AI Token Optimization

  • Progressive Discovery: AI can understand what exists without loading all details
  • Massive Size Reduction: Up to 96.7% smaller for multiple framework instances
  • Token Efficiency: Shared framework context across all instances (~70KB once)
  • Selective Loading: Load only needed chunks (DTOs, Features, Services)
  • Smart Categorization: Automatic business domain inference and complexity analysis

๐Ÿ“ Generated Documentation Structure

Traditional Structure

docs/generated/
โ”œโ”€โ”€ mkdocs.yml                    # MkDocs configuration
โ”œโ”€โ”€ requirements.txt              # Dependencies
โ”œโ”€โ”€ framework_schema.json         # AI-optimized JSON with framework context
โ”œโ”€โ”€ site/                        # Built HTML documentation
โ””โ”€โ”€ docs/                        # Markdown content
    โ”œโ”€โ”€ index.md                 # Overview
    โ”œโ”€โ”€ features.md              # Features documentation
    โ”œโ”€โ”€ dtos.md                  # DTOs documentation
    โ””โ”€โ”€ application-services.md  # Services documentation

NEW: Chunked Structure (AI-Optimized)

docs/generated/ai_context/
โ”œโ”€โ”€ 01_framework_context.json           # Shared framework knowledge (70KB)
โ”œโ”€โ”€ 01_payment_gateway_context.json     # Instance overview (1-2KB)
โ”œโ”€โ”€ 01_payment_gateway_dtos.json        # DTO summaries (700B)
โ”œโ”€โ”€ 01_payment_gateway_dtos_details.json # Full DTO details (1-3KB)
โ”œโ”€โ”€ 01_payment_gateway_features.json    # Feature summaries (700B)
โ”œโ”€โ”€ 01_payment_gateway_features_details.json # Full feature details (1-3KB)
โ”œโ”€โ”€ 01_payment_gateway_services.json    # Service summaries (if any)
โ”œโ”€โ”€ 01_payment_gateway_services_details.json # Full service details
โ”œโ”€โ”€ 02_user_management_context.json     # Second instance overview
โ”œโ”€โ”€ 02_user_management_dtos.json        # Second instance DTOs
โ””โ”€โ”€ ...                                 # Additional instances

๐Ÿค– AI-Optimized JSON Schema Features

The enhanced JSON schema combines framework context with repository analysis for complete AI understanding:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Repository Schema with Framework Context",
  "schema_type": "ai_optimized_complete",
  
  "framework_context": {
    "framework_name": "Sincpro Framework",
    "core_principles": {/* Framework usage patterns and principles */},
    "key_features": {/* Framework capabilities and features */},
    "framework_execution_patterns": {/* How to execute features/services */}
  },
  
  "repository_analysis": {
    "metadata": {
      "architecture_patterns": ["DDD", "Clean Architecture"],
      "component_summary": { /* counts and statistics */ }
    },
    "components": {
      "dtos": [/* with AI hints for type classification */],
      "features": [/* with business domain inference */],
      "application_services": [/* with orchestration patterns */]
    }
  },
  
  "ai_integration": {
    "framework_integration": {
      "execution_patterns": {/* How to use framework with repository components */},
      "available_features": {/* Framework capabilities */}
    },
    "complete_understanding": {
      "framework_knowledge": "Loaded from hardcoded guide",
      "repository_knowledge": "Generated from code analysis",
      "ai_capability": "Complete understanding of framework usage + repository components"
    },
    "usage_synthesis": {
      "how_to_execute_features": {/* Real examples combining framework + repo */},
      "how_to_execute_services": {/* Real examples combining framework + repo */}
    },
    "embedding_suggestions": {
      "primary_entities": ["PaymentCommand", "UserCommand"],
      "business_capabilities": ["PaymentFeature", "UserFeature"]
    },
    "code_generation_hints": {
      "framework_patterns": ["command_pattern", "dependency_injection"],
      "common_imports": ["from sincpro_framework import..."]
    },
    "complexity_analysis": {
      "overall_complexity": "medium",
      "most_complex_components": ["ComplexService"]
    }
  }
}

๐ŸŽฏ Chunked JSON Benefits for AI Consumption

The new chunked approach provides significant advantages for AI systems:

๐Ÿ“Š Size Reduction Examples

  • Single Instance: Traditional 90KB โ†’ Chunked 10KB (89% reduction)
  • Two Instances: Traditional 180KB โ†’ Chunked 80KB (56% reduction)
  • Five Instances: Traditional 450KB โ†’ Chunked 110KB (76% reduction)
  • Twenty Instances: Traditional 1.8MB โ†’ Chunked 250KB (86% reduction)

๐Ÿง  Progressive AI Discovery Pattern

  1. Start with Framework Context (01_framework_context.json - 70KB)

    • Learn how to use Sincpro Framework
    • Understand patterns and principles
    • Get execution examples
  2. Instance Overview (01_<name>_context.json - 1-2KB each)

    • Quickly understand what components exist
    • See component counts and names
    • Identify available detail files
  3. Component Summaries (01_<name>_dtos.json - 700B each)

    • Get basic component information
    • Understand business domains
    • Assess complexity levels
  4. Detailed Information (01_<name>_dtos_details.json - 1-3KB each)

    • Load full component details when needed
    • Complete field information
    • Implementation details

๐Ÿค– AI Token Optimization

  • Traditional: Load everything at once (high token cost)
  • Chunked: Load progressively as needed (optimized token usage)
  • Reusability: Framework context shared across all instances
  • Selectivity: Load only relevant component types (DTOs, Features, Services)

โœจ Documentation Features

Traditional Markdown

  • ๐ŸŽจ Sincpro Theme: Beautiful violet corporate colors and professional styling
  • ๐Ÿ“ฑ Responsive Design: Works perfectly on desktop and mobile devices
  • ๐Ÿ” Full-Text Search: Find any component, method, or parameter instantly
  • ๐Ÿ“Š Component Overview: Summary tables with component counts and descriptions

AI-Optimized JSON

  • ๐Ÿง  Business Domain Inference: Automatic categorization (payments, users, orders)
  • ๐Ÿ“ˆ Complexity Assessment: Automatic complexity analysis for optimization
  • ๐Ÿ” Pattern Recognition: Identification of architectural patterns
  • ๐Ÿค– AI Hints: Rich metadata for AI understanding and code generation

๐ŸŽฏ Best Practices

  1. Document your DTOs: Add clear docstrings to your Data Transfer Objects
  2. Describe your Features: Include comprehensive docstrings for execute methods
  3. Name components clearly: Use descriptive names for better auto-generated docs
  4. Organize by domain: Group related features and services logically

Example of well-documented code:

class PaymentCommand(DataTransferObject):
    """Command for processing credit card payments.

    This DTO contains all necessary information to process
    a payment transaction through the payment gateway.
    """
    card_number: str  # Credit card number (PCI compliant)
    amount: float     # Payment amount in USD
    merchant_id: str  # Unique merchant identifier

@framework.feature(PaymentCommand)
class PaymentFeature(Feature):
    """Process payment transactions through external gateway.

    This feature handles the complete payment flow including
    validation, gateway communication, and response processing.
    """

    def execute(self, dto: PaymentCommand) -> PaymentResponse:
        """Execute payment processing.

        Args:
            dto: Payment command with card and amount information

        Returns:
            PaymentResponse: Transaction result with ID and status

        Raises:
            PaymentError: When payment fails or card is invalid
        """
        # Implementation here...

๐Ÿš€ Integration with AI Systems

The JSON schema format enables powerful AI integrations:

  • Code Generation: AI can understand patterns and generate similar code
  • Documentation: AI can explain components and their relationships
  • Analysis: AI can identify optimization opportunities and suggest improvements
  • Migration: AI can understand dependencies for migration planning

Configuration or settings

The framework comes with a module or component to allow us to create configuratio or settings based on files or environment variables. You need to inherit from SincproConfig from module sincpro_framework.sincpro_conf

from sincpro_framework.sincpro_conf import SincproConfig


class PostgresConf(SincproConfig):
    host: str = "localhost"
    port: int = 5432
    user: str = "my_user"


class MyConfig(SincproConfig):
    log_level: str = "DEBUG"
    token: str = "defult_my_token"
    postgresql: PostgresConf = PostgresConf()

This class should be mapped based on yaml file like this, we have a feature to use ENV variables in the yaml file using the prefix $ENV:

log_level: "INFO"
token: "$ENV:MY_SECRET_TOKEN"
postgresql:
  host: localhost
  port: 12345
  user: custom_user

Environment Variable Handling

When using $ENV: prefix in your configuration files, the framework will:

  1. Look for the environment variable specified after $ENV:
  2. If the environment variable exists, use its value
  3. If the environment variable doesn't exist:
    • Use the default value defined in your configuration class
    • Issue a warning indicating that the environment variable is missing
    • Proceed with execution rather than raising an error

This behavior allows applications to run with partial configurations in development environments or when not all environment variables are available, while still logging appropriate warnings.

Example of fallback to default values:

# Configuration class with default
class ApiConfig(SincproConfig):
    api_key: str = "dev_default_key"  # Default value as fallback

# In config.yml
api_key: "$ENV:API_KEY"  # References environment variable

# If API_KEY environment variable is not set, the framework will:
# 1. Log a warning: "Environment variable [API_KEY] is not set for field [api_key]. Using default value: dev_default_key"
# 2. Use the default value "dev_default_key"
# 3. Continue execution without error

Then you can use the config object in your code where it will be loaded all the settings from the yaml file for that you will require use the following funciton build_config_obj

from sincpro_framework.sincpro_conf import build_config_obj
from .my_config import MyConfig

config = build_config_obj(MyConfig, '/path/to/your/config.yml')

assert isinstance(config.log_level, str)
assert isinstance(config.postgresql, PostgresConf)

๐Ÿ“ฆ Variables

The framework use a default setting file where live in the module folder inside of sincpro_framework/conf/sincpro_framework_conf.yml where you can define some behavior currently we support the following settings:

  • log level(sincpro_framework_log_level): Define the log level for the logger, the default is DEBUG

Override the config file using another

export SINCPRO_FRAMEWORK_CONFIG_FILE = /path/to/your/config.yml

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

sincpro_framework-3.0.3.tar.gz (72.5 kB view details)

Uploaded Source

Built Distribution

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

sincpro_framework-3.0.3-py3-none-any.whl (77.2 kB view details)

Uploaded Python 3

File details

Details for the file sincpro_framework-3.0.3.tar.gz.

File metadata

  • Download URL: sincpro_framework-3.0.3.tar.gz
  • Upload date:
  • Size: 72.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for sincpro_framework-3.0.3.tar.gz
Algorithm Hash digest
SHA256 6f33ee02831d2ec0c22013887f43bb08fd8563d687815d4ee174e09a3d2f6240
MD5 421710fdf6552a820c6766c43c2395e3
BLAKE2b-256 791cc31f667757a32562554f2e41bd2d36a8e4572631a118635fba0bfc84f109

See more details on using hashes here.

File details

Details for the file sincpro_framework-3.0.3-py3-none-any.whl.

File metadata

  • Download URL: sincpro_framework-3.0.3-py3-none-any.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for sincpro_framework-3.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a800b43d5d9e93b53d16e5c81aae4765aa5d6e08031a8a5bf6e0ecbc5ce1b07
MD5 29559ffe598e4af1b9f1facb8e137c23
BLAKE2b-256 66aae5d2d93ce9caf7ae700c614628f5d831e826906674867ba1b6e7c65bff86

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