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.1.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.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylaag_core-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 98b6ba6555fd6c38bf3f690e21987fce9ac7b1183d3d8f4a207b1aea539b9443
MD5 170fb6b04851f17b364e55e36311b3b2
BLAKE2b-256 93089d363dc2ea703946b061116bc72a2a67286150b9ee33db001ff6431af3a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylaag_core-0.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3ba5e07944f79ba03322fb8e9e4d2c7e446a771330205a87a2871284eb499c5
MD5 8e9245d1edf8195a75955155dc62d5fe
BLAKE2b-256 08ab4b26655f0150eb4dc2e477df5a82b5e575c40de3c3af0080913dd605f6a2

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