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.2.0.tar.gz (4.9 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.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylaag_raml-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 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.2.0.tar.gz
Algorithm Hash digest
SHA256 7b2d65da7630242f881f527e96b2c840b2964f40230b442dcb4c97c16d63e820
MD5 3bbd0404afec6642c66e8c6681038b5d
BLAKE2b-256 9fb74e6644151c0b6ad7109b950d8d1f1097dc09838d394fa9ef0c054ab4fb28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylaag_raml-0.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10ab0677cf38e608c521798ab152854336c3494a8cad2b64b4a81a65662af4cd
MD5 79cabebf6d13b1386ffc1cc06136528d
BLAKE2b-256 7fc8c0ab7d61d86c02a5cd1222d98c183acb929b29efcdf96135770a8b2107de

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