Skip to main content

MontyCloud DAY2 SDK for Python

Project description

MontyCloud SDK

A Python SDK for interacting with the MontyCloud DAY2 API.

Features

  • AWS-style client factories for simplified access
  • Secure authentication with API key and API secret key
  • Multi-tenant context management
  • Comprehensive error handling with retry logic
  • Strongly typed models using Pydantic
  • CLI interface for common operations

Requirements

  • Python 3.11 or higher

Installation

pip install day2

Quick Start

Using the SDK

Method 1: AWS-style Client Factories

import day2

# Use module-level client factories (automatically creates a default session)
tenants = day2.tenant().list_tenants()

for tenant in tenants.tenants:
    print(f"Tenant: {tenant.name} (ID: {tenant.id})")

# List assessments
assessments = day2.assessment().list_assessments(
    tenant_id="tenant-123",
    status="PENDING"
)

for assessment in assessments.assessments:
    print(f"Assessment: {assessment.name} (ID: {assessment.id})")

Method 2: Explicit Session

import day2

# Create a session with API key
session = day2.Session(api_key="your-api-key", api_secret_key="your-api-secret-key")

# List tenants
tenants = session.tenant.list_tenants()

for tenant in tenants.tenants:
    print(f"Tenant: {tenant.name} (ID: {tenant.id})")

# Set tenant context
session.set_tenant("tenant-123")

# List assessments in the tenant
assessments = session.assessment.list_assessments(tenant_id="tenant-123", status="PENDING")

for assessment in assessments.assessments:
    print(f"Assessment: {assessment.name} (ID: {assessment.id})")

Using the CLI

Configure authentication:

day2 auth configure --api-key your-api-key --api-secret-key your-api-secret-key

List tenants:

day2 tenant list

Get details of a specific tenant:

day2 tenant get tenant-123

List questions for a specific pillar in an assessment:

day2 assessment questions tenant-123 assessment-456 operational-excellence

Create a new assessment:

day2 assessment create tenant-123 \
    --name "My Assessment" \
    --description "My assessment description" \
    --review-owner "user@example.com" \
    --scope '{"AccountId": "123456789012"}' \
    --lenses "AWS Well-Architected Framework"

Authentication

The SDK supports authentication with both an API key and an API secret key. You can provide these credentials in several ways:

  1. Directly in code:

    # Simplified API
    session = day2.Session(api_key="your-api-key", api_secret_key="your-secret-key")
    
    # With API secret key
    session = day2.Session(
        api_key="your-api-key",
        api_secret_key="your-api-secret-key"
    )
    
  2. Environment variables:

    export DAY2_API_KEY="your-api-key"
    export DAY2_API_SECRET_KEY="your-api-secret-key"
    
    # Will use the environment variables
    session = day2.Session()
    # Or use the default session
    session = day2.get_default_session()
    
  3. Configuration file:

    # Using the CLI to configure
    day2 auth configure --api-key your-api-key --api-secret-key your-api-secret-key
    
    # Will use the configuration file
    session = day2.Session()
    # Or use the default session
    session = day2.get_default_session()
    

Multi-Tenant Support

The SDK supports multi-tenant operations through session-based tenant context:

# Create a session
session = day2.Session(api_key="your-api-key", api_secret_key="your-secret-key")

# Set tenant context
session.set_tenant("org-123")

# Operations will now be performed in the context of the tenant
assessments = session.assessment.list_assessments(tenant_id="tenant-123", status="PENDING")

# Switch to a different tenant
session.set_tenant("tenant-456")

# Operations will now be performed in the context of the new tenant
assessments = session.assessment.list_assessments(tenant_id="tenant-456", status="PENDING")

# Clear tenant context
session.clear_tenant()

You can also use the default session with module-level client factories:

# Get the default session and set tenant context
default_session = day2.get_default_session()
default_session.set_tenant("org-123")

# Now all module-level client factories will use this tenant context
assessments = day2.assessment().list_assessments(tenant_id="tenant-123", status="PENDING")

Running Examples

The SDK comes with example scripts in the examples directory that demonstrate various features. To run these examples:

  1. Clone the repository:

    git clone https://github.com/montycloud/day2-sdk.git
    cd day2-sdk
    
  2. Create a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install the package in development mode:

    pip install -e .
    
  4. Run an example:

    python examples/basic_usage.py
    

Note: Some examples may require you to have valid API credentials. Make sure to set up your authentication as described in the Authentication section before running the examples.

Error Handling

The SDK provides comprehensive error handling with custom exceptions:

import day2
from day2.exceptions import (
    ClientError,
    ServerError,
    ValidationError,
    ResourceNotFoundError,
    AuthenticationError,
    TenantContextError,
)

try:
    # Using module-level client factory
    tenant = day2.tenant().get_tenant("tenant-nonexistent")
except ResourceNotFoundError as e:
    print(f"Resource not found: {e}")
except ClientError as e:
    print(f"Client error: {e}")
except ServerError as e:
    print(f"Server error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Development

Documentation

The project uses MkDocs for documentation. Here are the available commands:

# Build documentation locally
make docs

# Serve documentation for local development
make serve-docs

# Deploy documentation to GitHub Pages (from main branch)
make deploy-docs

# Deploy documentation from any branch to GitHub Pages
make deploy-branch-docs

The deploy-branch-docs command is useful for:

  • Testing documentation changes before merging to main
  • Deploying documentation from feature branches
  • Creating documentation previews for pull requests

Note: deploy-branch-docs will overwrite the current GitHub Pages content, so use with caution in production environments.

Other Development Commands

# Run tests
make test

# Run linting
make lint

# Format code
make format

# Run type checking
make mypy

# Run all CI checks
make ci

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

day2-0.2.3.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

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

day2-0.2.3-py3-none-any.whl (73.0 kB view details)

Uploaded Python 3

File details

Details for the file day2-0.2.3.tar.gz.

File metadata

  • Download URL: day2-0.2.3.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for day2-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5ca69d42dc50f3990519c2256fa861068faa9735c32c6652fdbe6d9392d2a565
MD5 af463072f168585d811c146efe22f874
BLAKE2b-256 dccd98ff33e5c7b7849c6c96a2e0d8f94c2af51b4e9e636681aa766a0f1137ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for day2-0.2.3.tar.gz:

Publisher: publish.yml on montycloud/day2-sdk

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

File details

Details for the file day2-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: day2-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 73.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for day2-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a82644f77c9b702945bb92ac42f72248ccb5fced5c5551496711af78cebaa96
MD5 aa9939e8cde12562e29a5873ac7ba008
BLAKE2b-256 1c1e064a3ae80290b9cf13759f35231fa2b67fce373e82c66788eed237c64e77

See more details on using hashes here.

Provenance

The following attestation bundles were made for day2-0.2.3-py3-none-any.whl:

Publisher: publish.yml on montycloud/day2-sdk

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