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 enumsods-models-py- Pydantic data models
License
PROPRIETARY - Optikka
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optikka_design_data_layer-0.1.33.tar.gz.
File metadata
- Download URL: optikka_design_data_layer-0.1.33.tar.gz
- Upload date:
- Size: 41.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096aeb59a99ea53ed1ce89ebd124314ed1235557a765b303f8c82849ef87cdd7
|
|
| MD5 |
db2b628ed19d50dc95e9463875392866
|
|
| BLAKE2b-256 |
077be2c1ef08accb05f13c42cbc5bea404b0bb201e15b9e27d4d7b8ceaa39098
|
Provenance
The following attestation bundles were made for optikka_design_data_layer-0.1.33.tar.gz:
Publisher:
python-publish.yml on OptikkaCorp/design-models-package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optikka_design_data_layer-0.1.33.tar.gz -
Subject digest:
096aeb59a99ea53ed1ce89ebd124314ed1235557a765b303f8c82849ef87cdd7 - Sigstore transparency entry: 820400407
- Sigstore integration time:
-
Permalink:
OptikkaCorp/design-models-package@48ef2ed7bb27e75088b0e55ba0fce2be8a421e48 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/OptikkaCorp
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@48ef2ed7bb27e75088b0e55ba0fce2be8a421e48 -
Trigger Event:
push
-
Statement type:
File details
Details for the file optikka_design_data_layer-0.1.33-py3-none-any.whl.
File metadata
- Download URL: optikka_design_data_layer-0.1.33-py3-none-any.whl
- Upload date:
- Size: 49.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d84a62fda3bc7975794c0d04bc4792fd552dc144cb96ae4afa6acb4ee16ba747
|
|
| MD5 |
285ef29938f3548f756911bf5e37dacb
|
|
| BLAKE2b-256 |
7f97256df8d5357a0b84bb1331d72c39366a1ff70a8383f5ea933b5350bed2ba
|
Provenance
The following attestation bundles were made for optikka_design_data_layer-0.1.33-py3-none-any.whl:
Publisher:
python-publish.yml on OptikkaCorp/design-models-package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optikka_design_data_layer-0.1.33-py3-none-any.whl -
Subject digest:
d84a62fda3bc7975794c0d04bc4792fd552dc144cb96ae4afa6acb4ee16ba747 - Sigstore transparency entry: 820400424
- Sigstore integration time:
-
Permalink:
OptikkaCorp/design-models-package@48ef2ed7bb27e75088b0e55ba0fce2be8a421e48 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/OptikkaCorp
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@48ef2ed7bb27e75088b0e55ba0fce2be8a421e48 -
Trigger Event:
push
-
Statement type: