Skip to main content

RAML document manipulation for Python

Project description

pylaag-raml

RAML document manipulation for Python.

Overview

pylaag-raml provides comprehensive support for working with RAML 1.0 and 0.8 specifications, including:

  • Document parsing and serialization (YAML)
  • Resource and method management
  • Type definition management
  • Trait management
  • Document validation

Installation

pip install pylaag-raml

This will automatically install pylaag-core and pyyaml as dependencies.

Quick Start

from pylaag_raml import RAMLDocument

# Parse a RAML document
doc = RAMLDocument.from_yaml(raml_content)
doc.validate()

# Access document properties
print(doc.title)
print(doc.version)
print(doc.base_uri)

# Serialize back to YAML
yaml_output = doc.to_yaml()

Features

Document Management

from pylaag_raml import RAMLDocument

# Create a new document
doc = RAMLDocument()

# Parse from YAML
doc = RAMLDocument.from_yaml(yaml_string)

# Validate document
doc.validate()  # Raises ValidationError if invalid

# Access properties
print(doc.title)
print(doc.version)
print(doc.base_uri)

Resource Management

from pylaag_raml import RAMLDocument, ResourceManager

doc = RAMLDocument()
resource_mgr = ResourceManager(doc)

# Add a resource
resource_mgr.add_resource('/users', {
    'displayName': 'Users',
    'description': 'User management endpoints'
})

# Add a method to a resource
resource_mgr.add_method('/users', 'get', {
    'description': 'List all users',
    'responses': {
        '200': {
            'body': {
                'application/json': {
                    'type': 'User[]'
                }
            }
        }
    }
})

# Get a resource
resource = resource_mgr.get_resource('/users')

# Remove a method
resource_mgr.remove_method('/users', 'get')

# Remove a resource
resource_mgr.remove_resource('/users')

Type Management

from pylaag_raml import RAMLDocument, TypeManager

doc = RAMLDocument()
type_mgr = TypeManager(doc)

# Add a type definition
type_mgr.add_type('User', {
    'type': 'object',
    'properties': {
        'id': {
            'type': 'integer',
            'required': True
        },
        'name': {
            'type': 'string',
            'required': True
        },
        'email': {
            'type': 'string',
            'required': True
        }
    }
})

# Get a type
user_type = type_mgr.get_type('User')

# Remove a type
type_mgr.remove_type('User')

Extension Properties

from pylaag_raml import RAMLDocument

doc = RAMLDocument()

# Set extension property
doc.set_extension('x-api-id', 'my-api-123')

# Get extension property
api_id = doc.get_extension('x-api-id')

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

API Reference

Classes

RAMLDocument

Main class for working with RAML documents.

Class Methods:

  • from_yaml(yaml_str: str) -> RAMLDocument: Parse from YAML string

Methods:

  • validate() -> None: Validate the document structure
  • to_yaml() -> str: Serialize to YAML string

Properties:

  • title: str: The API title
  • version: str: The API version
  • base_uri: str: The base URI for the API

ResourceManager

Manages resources and methods in a RAML document.

Methods:

  • add_resource(path: str, resource: Optional[Dict] = None) -> None
  • remove_resource(path: str) -> bool
  • get_resource(path: str) -> Optional[Dict]
  • add_method(path: str, method: str, method_def: Dict) -> None
  • remove_method(path: str, method: str) -> bool

TypeManager

Manages type definitions in a RAML document.

Methods:

  • add_type(name: str, type_def: Dict) -> None
  • remove_type(name: str) -> bool
  • get_type(name: str) -> Optional[Dict]

Requirements

  • Python 3.10 or higher
  • pylaag-core >= 0.1.0
  • pyyaml >= 6.0.1

License

MIT License - see LICENSE file for details

Related Packages

Contributing

Contributions are welcome! Please see the main repository for guidelines.

Links

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_raml-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

pylaag_raml-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylaag_raml-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 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_raml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c14e74a790a9af0f459e2fc4c0932168417ccd6b4de113d3e86517d6c966d1f6
MD5 a831979bbed3aaa8f0bd843a4bec1832
BLAKE2b-256 476343d5e02d6f9ee3babcfb99f7209331c6964f62574305d7b80d7a0022c2c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylaag_raml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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_raml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 787667674411b4fe4ff5a7b7cd8f1cfbd07f0428af79a68de1acf479d846084d
MD5 8ef9d748f7f05c9d4d833ef310fbeec3
BLAKE2b-256 8c91391ba92055d7a6b492217884df0d2e7d5339ee6cc5c6933e040144e0f980

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