Skip to main content

Shared utilities for Optikka microservices (logger, errors, response utils, auth validation, database clients, AI clients)

Project description

optikka-design-data-layer

Shared design data layer utilities for Optikka microservices running on AWS Lambda.

This package provides AWS service clients, database connections, validators, and utilities for Lambda functions in the design-data-microservices ecosystem.

Installation

pip install optikka-design-data-layer

Usage

Database Clients

from optikka_design_data_layer.clients import mongodb_client, postgres_client

# MongoDB operations
template = mongodb_client.get_template_registry_by_id("template-123")

# PostgreSQL operations
result = postgres_client.execute_query("SELECT * FROM images WHERE id = %s", ("image-123",))

AWS Services

from optikka_design_data_layer.aws import (
    upload_script_to_s3,
    SecretsManager,
    BedrockClient,
    OpenAIClient,
)

# S3 operations
s3_location = upload_script_to_s3("my-script-content", "script.js")

# Secrets Manager
secrets = SecretsManager()
api_key = secrets.get_secret("my-secret-arn")

# AI clients
bedrock = BedrockClient()
openai = OpenAIClient()

Validation

from optikka_design_data_layer.validation import (
    validate_auth_from_event,
    TemplateInputValidator,
)
from ods_models import TemplateInput, TemplateRegistry

# Auth validation
if validate_auth_from_event(event, secret_name):
    # Process authenticated request
    pass

# Template input validation
validator = TemplateInputValidator()
is_valid, errors = validator.validate(template_input, template_registry)

Utilities

from optikka_design_data_layer.utils import (
    create_success_response,
    create_error_response,
    get_all_guide_data_by_image,
)

# Lambda response utilities
return create_success_response(data={"message": "Success"})
return create_error_response(500, "Internal server error")

# Asset data utilities
guides = get_all_guide_data_by_image(images)

Configuration and Logging

from optikka_design_data_layer import logger, EnvironmentVariables

# Logging (AWS Lambda Powertools)
logger.info("Processing request")
logger.error("Error occurred", exc_info=True)

# Environment variables
db_name = EnvironmentVariables.MONGODB_DATABASE_NAME
bucket = EnvironmentVariables.S3_BUCKET_PREFIX

Package Structure

optikka_design_data_layer/
├── clients/           # Database clients
│   ├── mongo_client.py
│   ├── postgres_client.py
│   ├── postgres_credential_manager.py
│   └── mongodb_guide_client.py
├── aws/               # AWS service clients
│   ├── s3_utils.py
│   ├── secrets_manager.py
│   ├── bedrock_client.py
│   └── openai_client.py
├── validation/        # Validators
│   ├── validate_auth.py
│   └── validate_template_input_object.py
├── utils/             # Utilities
│   ├── response_utils.py
│   └── get_asset_data_by_image.py
├── logger.py          # AWS Lambda Powertools logger
├── config.py          # Environment variables
├── errors.py          # Custom exceptions
└── connection_types.py # Connection types

Dependencies

  • ods-models-py: Pydantic data models
  • boto3: AWS SDK for Python
  • pymongo: MongoDB driver
  • psycopg2-binary: PostgreSQL adapter
  • aws-lambda-powertools: AWS Lambda utilities
  • pydantic: Data validation
  • openai: OpenAI client
  • And more...

Migration from Lambda Layer

Old (Lambda layer imports)

from logger import logger  # pylint: disable=import-error
from models import TemplateRegistry  # pylint: disable=import-error
from mongo_client import mongodb_client  # pylint: disable=import-error

New (pip package imports)

from optikka_design_data_layer import logger
from ods_models import TemplateRegistry
from optikka_design_data_layer.clients import mongodb_client

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/

# Lint
ruff check src/ tests/

Related Packages

  • ods-types-py - Core types and enums
  • ods-models-py - Pydantic data models

License

PROPRIETARY - Optikka

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

optikka_design_data_layer-0.1.44.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

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

optikka_design_data_layer-0.1.44-py3-none-any.whl (50.7 kB view details)

Uploaded Python 3

File details

Details for the file optikka_design_data_layer-0.1.44.tar.gz.

File metadata

File hashes

Hashes for optikka_design_data_layer-0.1.44.tar.gz
Algorithm Hash digest
SHA256 4765c708aa3f43f9ef07cd5e369196bda4c0cf6cc818c55a46baf8597f37f072
MD5 21104656388a83f0c45c0483857ec59e
BLAKE2b-256 1c9be1d2de1738a4ed6475f5ddaa9c26e1ec41f3100c7b2ca47e568424116085

See more details on using hashes here.

Provenance

The following attestation bundles were made for optikka_design_data_layer-0.1.44.tar.gz:

Publisher: python-publish.yml on OptikkaCorp/design-models-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file optikka_design_data_layer-0.1.44-py3-none-any.whl.

File metadata

File hashes

Hashes for optikka_design_data_layer-0.1.44-py3-none-any.whl
Algorithm Hash digest
SHA256 cbd516af2f1171b231ea6e9a14058a728e4e7a3e0fa10403c084c9030a5900dd
MD5 e44c2cef8d11cfbd84b93b2eec552e00
BLAKE2b-256 f050ed0ba8f9f5f1306075abd252954787d4d35fa1db4654f561d27ddf1e0ff9

See more details on using hashes here.

Provenance

The following attestation bundles were made for optikka_design_data_layer-0.1.44-py3-none-any.whl:

Publisher: python-publish.yml on OptikkaCorp/design-models-package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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