Skip to main content

Core utilities and base classes for the laag Python library

Project description

pylaag-core

Core utilities and base classes for the laag Python library.

Overview

pylaag-core provides the foundational components used by all laag packages, including:

  • Base classes for API document handlers
  • Error handling system
  • Utility functions for nested object navigation
  • Extension property support

This package is typically installed as a dependency of other laag packages and is not used directly in most cases.

Installation

pip install pylaag-core

Features

  • LaagBase: Abstract base class for all API document handlers
  • Error Classes: Comprehensive exception hierarchy (LaagError, ValidationError, ParseError, NotFoundError)
  • Utility Functions: Helper functions for working with nested dictionaries
  • Extension Properties: Support for x-* custom properties in API documents
  • Type Safety: Full type hints for static analysis

Usage

Base Class

from pylaag.core import LaagBase

class MyDocument(LaagBase):
    def validate(self) -> None:
        # Implement validation logic
        if 'required_field' not in self._document:
            raise ValidationError("Missing required field")

Error Handling

from pylaag.core import ValidationError, ParseError, NotFoundError

try:
    doc.validate()
except ValidationError as e:
    print(f"Validation failed: {e}")
    print(f"Context: {e.context}")

Utility Functions

from pylaag.core import get_nested, set_nested, delete_nested

data = {'a': {'b': {'c': 1}}}

# Get nested value
value = get_nested(data, 'a.b.c')  # Returns 1

# Set nested value
set_nested(data, 'a.b.d', 2)  # data['a']['b']['d'] = 2

# Delete nested value
deleted = delete_nested(data, 'a.b.c')  # Returns True

Extension Properties

from pylaag.core import LaagBase

doc = MyDocument()

# Set extension property
doc.set_extension('x-custom', {'key': 'value'})

# Get extension property
custom = doc.get_extension('x-custom')

# Remove extension property
doc.remove_extension('x-custom')

API Reference

Classes

LaagBase

Abstract base class for all API document handlers.

Methods:

  • validate() -> None: Validate the document (must be implemented by subclasses)
  • get_extension(key: str) -> Optional[Any]: Get an extension property value
  • set_extension(key: str, value: Any) -> None: Set an extension property value
  • remove_extension(key: str) -> None: Remove an extension property
  • to_dict() -> Dict[str, Any]: Convert to dictionary representation

LaagError

Base exception class for all laag errors.

Attributes:

  • context: Dict[str, Any]: Additional context information about the error

ValidationError

Raised when document validation fails.

ParseError

Raised when document parsing fails.

NotFoundError

Raised when a requested resource is not found.

Functions

get_nested

def get_nested(obj: Dict[str, Any], path: str, default: Any = None) -> Any

Get a nested value from a dictionary using dot notation.

Parameters:

  • obj: The dictionary to search
  • path: Dot-separated path (e.g., 'a.b.c')
  • default: Default value if path not found

Returns: The value at the path, or default if not found

set_nested

def set_nested(obj: Dict[str, Any], path: str, value: Any) -> None

Set a nested value in a dictionary using dot notation.

Parameters:

  • obj: The dictionary to modify
  • path: Dot-separated path (e.g., 'a.b.c')
  • value: Value to set

delete_nested

def delete_nested(obj: Dict[str, Any], path: str) -> bool

Delete a nested value from a dictionary using dot notation.

Parameters:

  • obj: The dictionary to modify
  • path: Dot-separated path (e.g., 'a.b.c')

Returns: True if the value was deleted, False if not found

Requirements

  • Python 3.10 or higher

License

MIT License - see LICENSE file for details

Related Packages

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

pylaag_core-0.2.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

pylaag_core-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pylaag_core-0.2.0.tar.gz.

File metadata

  • Download URL: pylaag_core-0.2.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylaag_core-0.2.0.tar.gz
Algorithm Hash digest
SHA256 38788a73e7791e4102e6342f6898b32c89ba243320cc6c9f56ad693dec044d7a
MD5 e20c2810b965966b7a67327cb3b927c3
BLAKE2b-256 b1918e8a10cc681a8b7eed6d4f124af5498159bfa2bff4fd9c39fef3fb80498b

See more details on using hashes here.

File details

Details for the file pylaag_core-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pylaag_core-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylaag_core-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04c0cb6f393e19b44c82e76a2a646289f77b1d96ae23c9916309b91fe29ca1ea
MD5 ceea6bd56571e8bdf43196a57fca5a20
BLAKE2b-256 ee81d4c9e6146e50460a7bc698c8de4da0994f082a3cb2ccf7dd36b55f11b11f

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