its-compiler


Nameits-compiler JSON
Version 1.0.4 PyPI version JSON
download
home_pageNone
SummaryReference Python library for Instruction Template Specification (ITS) with comprehensive security features
upload_time2025-07-21 17:34:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords its instruction template specification ai prompt compilation nlp content-generation security library
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ITS Compiler

[![PyPI version](https://img.shields.io/pypi/v/its-compiler.svg)](https://pypi.org/project/its-compiler/)
[![Python](https://img.shields.io/pypi/pyversions/its-compiler.svg)](https://pypi.org/project/its-compiler/)
[![License](https://img.shields.io/github/license/AlexanderParker/its-compiler-python.svg)](LICENSE)

Reference Python compiler for the [Instruction Template Specification (ITS)](https://alexanderparker.github.io/instruction-template-specification/) that converts content templates with placeholders into structured AI prompts.

> **New to ITS?** See the [specification documentation](https://alexanderparker.github.io/instruction-template-specification/) for complete details on the template format and concepts.

## Installation

### For Library Users

```bash
pip install its-compiler
```

### Command Line Interface

For command-line usage, install the separate CLI package:

```bash
pip install its-compiler-cli
```

See the [ITS Compiler CLI repository](https://github.com/AlexanderParker/its-compiler-cli-python) for command-line documentation and usage examples.

### For Developers

```bash
# Clone and setup
git clone https://github.com/AlexanderParker/its-compiler-python.git
cd its-compiler-python

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Run tests
python test_runner.py
```

## Quick Example

**Input Template (`blog-post.json`):**

```json
{
  "$schema": "https://alexanderparker.github.io/instruction-template-specification/schema/v1.0/its-base-schema-v1.json",
  "version": "1.0.0",
  "extends": ["https://alexanderparker.github.io/instruction-template-specification/schema/v1.0/its-standard-types-v1.json"],
  "variables": {
    "topic": "sustainable technology",
    "includeExamples": true
  },
  "content": [
    {
      "type": "text",
      "text": "# "
    },
    {
      "type": "placeholder",
      "instructionType": "title",
      "config": {
        "description": "Create an engaging blog post title about ${topic}",
        "style": "catchy",
        "length": "short"
      }
    },
    {
      "type": "text",
      "text": "\n\n## Introduction\n\n"
    },
    {
      "type": "placeholder",
      "instructionType": "paragraph",
      "config": {
        "description": "Write an engaging introduction about ${topic}",
        "tone": "professional",
        "length": "medium"
      }
    },
    {
      "type": "conditional",
      "condition": "includeExamples == true",
      "content": [
        {
          "type": "text",
          "text": "\n\n## Examples\n\n"
        },
        {
          "type": "placeholder",
          "instructionType": "list",
          "config": {
            "description": "List 4 examples of ${topic}",
            "format": "bullet_points",
            "itemCount": 4
          }
        }
      ]
    }
  ]
}
```

**Using the Python Library:**

```python
from its_compiler import ITSCompiler

compiler = ITSCompiler()
result = compiler.compile_file('blog-post.json')
print(result.prompt)
```

**Output:**

```
INTRODUCTION

You are an AI assistant that fills in content templates. Follow the instructions exactly and replace each placeholder with appropriate content based on the user prompts provided. Respond only with the transformed content.

INSTRUCTIONS

1. Replace each placeholder marked with << >> with generated content
2. The user's content request is wrapped in ([{< >}]) to distinguish it from instructions
3. Follow the format requirements specified after each user prompt
4. Maintain the existing structure and formatting of the template
5. Only replace the placeholders - do not modify any other text
6. Generate content that matches the tone and style requested
7. Respond only with the transformed content - do not include any explanations or additional text

TEMPLATE

# <<Replace this placeholder with a title using this user prompt: ([{<Create an engaging blog post title about sustainable technology>}]). Format requirements: Create a catchy title that is short in length.>>

## Introduction

<<Replace this placeholder with text using this user prompt: ([{<Write an engaging introduction about sustainable technology>}]). Format requirements: Use professional tone and medium length (2-4 sentences).>>

## Examples

<<Replace this placeholder with a list using this user prompt: ([{<List 4 examples of sustainable technology>}]). Format requirements: Use bullet_points formatting with each item on a new line. Create exactly 4 items.>>
```

## Python Library Usage

### Basic Usage

```python
from its_compiler import ITSCompiler

# Initialize compiler
compiler = ITSCompiler()

# Compile a template file
result = compiler.compile_file('template.json')
print(result.prompt)

# Compile with custom variables
variables = {"productType": "gaming headset", "featureCount": 5}
result = compiler.compile(template_dict, variables=variables)

# Handle compilation errors
try:
    result = compiler.compile_file('template.json')
except ITSValidationError as e:
    print(f"Validation error: {e}")
except ITSCompilationError as e:
    print(f"Compilation error: {e}")
```

### Configuration

```python
from its_compiler import ITSCompiler, ITSConfig
from its_compiler.security import SecurityConfig

# Custom configuration
config = ITSConfig(
    cache_enabled=False,
    strict_mode=True,
    max_retries=5
)

# Security configuration
security_config = SecurityConfig.for_development()
security_config.allowlist.interactive_mode = False

compiler = ITSCompiler(config=config, security_config=security_config)
```

### Variables and Conditionals

```json
{
  "variables": {
    "product": { "name": "SmartWatch Pro", "price": 299 },
    "features": ["heart rate", "GPS", "waterproof"],
    "showSpecs": true
  },
  "content": [
    { "type": "text", "text": "# ${product.name}\nPrice: ${product.price}\n" },
    {
      "type": "conditional",
      "condition": "showSpecs == true and product.price > 200",
      "content": [{ "type": "text", "text": "Premium features included" }]
    }
  ]
}
```

**Variable support:**

- Simple values: `${productName}`
- Object properties: `${product.name}`, `${product.price}`
- Array elements: `${features[0]}`, array length: `${features.length}`
- Arrays as lists: `${features}` becomes "heart rate, GPS, waterproof"

**Conditional operators:**

- Comparison: `==`, `!=`, `<`, `<=`, `>`, `>=`
- Boolean: `and`, `or`, `not`
- Membership: `in`, `not in`

## Configuration

### Environment Variables

**Network Security:**

- `ITS_ALLOW_HTTP` - Allow HTTP URLs (default: false)
- `ITS_BLOCK_LOCALHOST` - Block localhost access (default: true)
- `ITS_REQUEST_TIMEOUT` - Network timeout in seconds (default: 10)
- `ITS_DOMAIN_ALLOWLIST` - Comma-separated allowed domains

**Schema Allowlist:**

- `ITS_INTERACTIVE_ALLOWLIST` - Enable interactive prompts (default: true)
- `ITS_ALLOWLIST_FILE` - Custom allowlist file location

**Processing Limits:**

- `ITS_MAX_TEMPLATE_SIZE` - Max template size in bytes (default: 1MB)
- `ITS_MAX_CONTENT_ELEMENTS` - Max content elements (default: 1000)

**Feature Toggles:**

- `ITS_DISABLE_ALLOWLIST` - Disable schema allowlist
- `ITS_DISABLE_INPUT_VALIDATION` - Disable input validation

### Allowlist Management

When `ITS_INTERACTIVE_ALLOWLIST` is enabled, you'll be prompted for unknown schemas:

```
SCHEMA ALLOWLIST DECISION REQUIRED
URL: https://example.com/schema.json

1. Allow permanently (saved to allowlist)
2. Allow for this session only
3. Deny (compilation will fail)
```

### Configuration File

Create `.its-config.json`:

```json
{
  "security": {
    "allowHttp": false,
    "domainAllowlist": ["alexanderparker.github.io"],
    "maxSchemaSize": "10MB"
  },
  "compiler": {
    "strictMode": true,
    "reportOverrides": true
  }
}
```

## Error Handling

The compiler provides detailed error messages:

### Schema Validation Errors

```
ITSValidationError: Template validation failed at content[2].config:
  - Missing required property 'description'
  - Invalid instruction type 'unknown_type'
```

### Variable Resolution Errors

```
ITSVariableError: Undefined variable reference at content[1].config.description:
  - Variable '${productName}' is not defined
  - Available variables: productType, featureCount
```

## Testing

```bash
# Run all tests
python test_runner.py

# Run specific categories
python test_runner.py --category security
python test_runner.py --category integration

# Run with verbose output
python test_runner.py --verbose

# Run linting and security checks
python test_runner.py --lint
python test_runner.py --security-scan
```

## API Reference

### Required Imports

```python
from typing import Optional
from its_compiler import ITSCompiler, ITSConfig
from its_compiler.security import SecurityConfig
from its_compiler.core.exceptions import ITSValidationError, ITSCompilationError
```

### ITSCompiler Class

```python
class ITSCompiler:
    def __init__(self, config: Optional[ITSConfig] = None,
                 security_config: Optional[SecurityConfig] = None)

    def compile(self, template: dict, variables: Optional[dict] = None,
                base_url: Optional[str] = None) -> CompilationResult

    def compile_file(self, template_path: str, variables: Optional[dict] = None) -> CompilationResult

    def validate(self, template: dict, base_url: Optional[str] = None) -> ValidationResult

    def validate_file(self, template_path: str) -> ValidationResult

    def get_security_status(self) -> dict
```

### CompilationResult Class

```python
class CompilationResult:
    prompt: str                           # The compiled prompt
    template: dict                        # The original template
    variables: dict                       # Resolved variables
    overrides: List[TypeOverride]         # Type overrides that occurred
    warnings: List[str]                   # Compilation warnings
    security_metrics: SecurityMetrics     # Security operation metrics
    compilation_time: Optional[float]     # Time taken to compile
    security_events: List[str]            # Security events that occurred

    # Properties
    @property
    def has_overrides(self) -> bool       # Check if any type overrides occurred

    @property
    def has_warnings(self) -> bool        # Check if any warnings were generated

    @property
    def has_security_events(self) -> bool # Check if any security events occurred

    @property
    def prompt_size(self) -> int          # Get prompt size in bytes

    # Methods
    def get_summary(self) -> dict         # Get compilation summary with metrics
```

### ValidationResult Class

```python
class ValidationResult:
    is_valid: bool                        # Whether validation passed
    errors: List[str]                     # Validation errors found
    warnings: List[str]                   # Validation warnings
    security_issues: List[str]            # Security issues found
    validation_time: Optional[float]      # Time taken to validate

    # Properties
    @property
    def has_security_issues(self) -> bool # Check if security issues were found

    @property
    def total_issues(self) -> int         # Get total count of all issues

    def __bool__(self) -> bool            # Allows `if validation_result:` usage
```

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`; other branch prefixes could be used i.e. `bugfix`, `devops`, `test`, etc, depending on use-case)
3. Make your changes and add / update tests, precommit configs, and github workflows as appropriate
4. Ensure all tests pass (`python test_runner.py --all`)
5. Commit your changes
6. Push to the branch and ensure all github workflows pass
7. Open a Pull Request

### Development Setup

```bash
# Clone and setup
git clone https://github.com/AlexanderParker/its-compiler-python.git
cd its-compiler-python

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Run tests
python test_runner.py
```

### For Maintainers

**Publishing to PyPI:**

This package is published to PyPI as `its-compiler`. Releases are currently managed manually:

```bash
# Build the package
python -m build

# Test upload to TestPyPI first (recommended)
python -m twine upload --repository testpypi dist/*

# Upload to production PyPI (requires appropriate credentials)
python -m twine upload dist/*
```

**TestPyPI Testing:**

```bash
# Install from TestPyPI to verify the package
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ its-compiler
```

## Related Projects

- **[ITS Compiler CLI](https://github.com/AlexanderParker/its-compiler-cli-python)** - Command-line interface for the ITS Compiler
- **[Instruction Template Specification](https://alexanderparker.github.io/instruction-template-specification/)** - The official ITS specification and schema
- **[ITS Example Templates](https://github.com/AlexanderParker/its-example-templates)** - Test templates and examples for the ITS compiler

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "its-compiler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Alexander Parker <pypi@parker.im>",
    "keywords": "its, instruction, template, specification, ai, prompt, compilation, nlp, content-generation, security, library",
    "author": null,
    "author_email": "Alexander Parker <pypi@parker.im>",
    "download_url": "https://files.pythonhosted.org/packages/a8/c5/628660fdc7476c604bbd5d4fb48d916fe44d95216f4b1cbe3e30120f67c4/its_compiler-1.0.4.tar.gz",
    "platform": null,
    "description": "# ITS Compiler\r\n\r\n[![PyPI version](https://img.shields.io/pypi/v/its-compiler.svg)](https://pypi.org/project/its-compiler/)\r\n[![Python](https://img.shields.io/pypi/pyversions/its-compiler.svg)](https://pypi.org/project/its-compiler/)\r\n[![License](https://img.shields.io/github/license/AlexanderParker/its-compiler-python.svg)](LICENSE)\r\n\r\nReference Python compiler for the [Instruction Template Specification (ITS)](https://alexanderparker.github.io/instruction-template-specification/) that converts content templates with placeholders into structured AI prompts.\r\n\r\n> **New to ITS?** See the [specification documentation](https://alexanderparker.github.io/instruction-template-specification/) for complete details on the template format and concepts.\r\n\r\n## Installation\r\n\r\n### For Library Users\r\n\r\n```bash\r\npip install its-compiler\r\n```\r\n\r\n### Command Line Interface\r\n\r\nFor command-line usage, install the separate CLI package:\r\n\r\n```bash\r\npip install its-compiler-cli\r\n```\r\n\r\nSee the [ITS Compiler CLI repository](https://github.com/AlexanderParker/its-compiler-cli-python) for command-line documentation and usage examples.\r\n\r\n### For Developers\r\n\r\n```bash\r\n# Clone and setup\r\ngit clone https://github.com/AlexanderParker/its-compiler-python.git\r\ncd its-compiler-python\r\n\r\n# Create virtual environment\r\npython -m venv venv\r\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\r\n\r\n# Install in development mode\r\npip install -e \".[dev]\"\r\n\r\n# Run tests\r\npython test_runner.py\r\n```\r\n\r\n## Quick Example\r\n\r\n**Input Template (`blog-post.json`):**\r\n\r\n```json\r\n{\r\n  \"$schema\": \"https://alexanderparker.github.io/instruction-template-specification/schema/v1.0/its-base-schema-v1.json\",\r\n  \"version\": \"1.0.0\",\r\n  \"extends\": [\"https://alexanderparker.github.io/instruction-template-specification/schema/v1.0/its-standard-types-v1.json\"],\r\n  \"variables\": {\r\n    \"topic\": \"sustainable technology\",\r\n    \"includeExamples\": true\r\n  },\r\n  \"content\": [\r\n    {\r\n      \"type\": \"text\",\r\n      \"text\": \"# \"\r\n    },\r\n    {\r\n      \"type\": \"placeholder\",\r\n      \"instructionType\": \"title\",\r\n      \"config\": {\r\n        \"description\": \"Create an engaging blog post title about ${topic}\",\r\n        \"style\": \"catchy\",\r\n        \"length\": \"short\"\r\n      }\r\n    },\r\n    {\r\n      \"type\": \"text\",\r\n      \"text\": \"\\n\\n## Introduction\\n\\n\"\r\n    },\r\n    {\r\n      \"type\": \"placeholder\",\r\n      \"instructionType\": \"paragraph\",\r\n      \"config\": {\r\n        \"description\": \"Write an engaging introduction about ${topic}\",\r\n        \"tone\": \"professional\",\r\n        \"length\": \"medium\"\r\n      }\r\n    },\r\n    {\r\n      \"type\": \"conditional\",\r\n      \"condition\": \"includeExamples == true\",\r\n      \"content\": [\r\n        {\r\n          \"type\": \"text\",\r\n          \"text\": \"\\n\\n## Examples\\n\\n\"\r\n        },\r\n        {\r\n          \"type\": \"placeholder\",\r\n          \"instructionType\": \"list\",\r\n          \"config\": {\r\n            \"description\": \"List 4 examples of ${topic}\",\r\n            \"format\": \"bullet_points\",\r\n            \"itemCount\": 4\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n**Using the Python Library:**\r\n\r\n```python\r\nfrom its_compiler import ITSCompiler\r\n\r\ncompiler = ITSCompiler()\r\nresult = compiler.compile_file('blog-post.json')\r\nprint(result.prompt)\r\n```\r\n\r\n**Output:**\r\n\r\n```\r\nINTRODUCTION\r\n\r\nYou are an AI assistant that fills in content templates. Follow the instructions exactly and replace each placeholder with appropriate content based on the user prompts provided. Respond only with the transformed content.\r\n\r\nINSTRUCTIONS\r\n\r\n1. Replace each placeholder marked with << >> with generated content\r\n2. The user's content request is wrapped in ([{< >}]) to distinguish it from instructions\r\n3. Follow the format requirements specified after each user prompt\r\n4. Maintain the existing structure and formatting of the template\r\n5. Only replace the placeholders - do not modify any other text\r\n6. Generate content that matches the tone and style requested\r\n7. Respond only with the transformed content - do not include any explanations or additional text\r\n\r\nTEMPLATE\r\n\r\n# <<Replace this placeholder with a title using this user prompt: ([{<Create an engaging blog post title about sustainable technology>}]). Format requirements: Create a catchy title that is short in length.>>\r\n\r\n## Introduction\r\n\r\n<<Replace this placeholder with text using this user prompt: ([{<Write an engaging introduction about sustainable technology>}]). Format requirements: Use professional tone and medium length (2-4 sentences).>>\r\n\r\n## Examples\r\n\r\n<<Replace this placeholder with a list using this user prompt: ([{<List 4 examples of sustainable technology>}]). Format requirements: Use bullet_points formatting with each item on a new line. Create exactly 4 items.>>\r\n```\r\n\r\n## Python Library Usage\r\n\r\n### Basic Usage\r\n\r\n```python\r\nfrom its_compiler import ITSCompiler\r\n\r\n# Initialize compiler\r\ncompiler = ITSCompiler()\r\n\r\n# Compile a template file\r\nresult = compiler.compile_file('template.json')\r\nprint(result.prompt)\r\n\r\n# Compile with custom variables\r\nvariables = {\"productType\": \"gaming headset\", \"featureCount\": 5}\r\nresult = compiler.compile(template_dict, variables=variables)\r\n\r\n# Handle compilation errors\r\ntry:\r\n    result = compiler.compile_file('template.json')\r\nexcept ITSValidationError as e:\r\n    print(f\"Validation error: {e}\")\r\nexcept ITSCompilationError as e:\r\n    print(f\"Compilation error: {e}\")\r\n```\r\n\r\n### Configuration\r\n\r\n```python\r\nfrom its_compiler import ITSCompiler, ITSConfig\r\nfrom its_compiler.security import SecurityConfig\r\n\r\n# Custom configuration\r\nconfig = ITSConfig(\r\n    cache_enabled=False,\r\n    strict_mode=True,\r\n    max_retries=5\r\n)\r\n\r\n# Security configuration\r\nsecurity_config = SecurityConfig.for_development()\r\nsecurity_config.allowlist.interactive_mode = False\r\n\r\ncompiler = ITSCompiler(config=config, security_config=security_config)\r\n```\r\n\r\n### Variables and Conditionals\r\n\r\n```json\r\n{\r\n  \"variables\": {\r\n    \"product\": { \"name\": \"SmartWatch Pro\", \"price\": 299 },\r\n    \"features\": [\"heart rate\", \"GPS\", \"waterproof\"],\r\n    \"showSpecs\": true\r\n  },\r\n  \"content\": [\r\n    { \"type\": \"text\", \"text\": \"# ${product.name}\\nPrice: ${product.price}\\n\" },\r\n    {\r\n      \"type\": \"conditional\",\r\n      \"condition\": \"showSpecs == true and product.price > 200\",\r\n      \"content\": [{ \"type\": \"text\", \"text\": \"Premium features included\" }]\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n**Variable support:**\r\n\r\n- Simple values: `${productName}`\r\n- Object properties: `${product.name}`, `${product.price}`\r\n- Array elements: `${features[0]}`, array length: `${features.length}`\r\n- Arrays as lists: `${features}` becomes \"heart rate, GPS, waterproof\"\r\n\r\n**Conditional operators:**\r\n\r\n- Comparison: `==`, `!=`, `<`, `<=`, `>`, `>=`\r\n- Boolean: `and`, `or`, `not`\r\n- Membership: `in`, `not in`\r\n\r\n## Configuration\r\n\r\n### Environment Variables\r\n\r\n**Network Security:**\r\n\r\n- `ITS_ALLOW_HTTP` - Allow HTTP URLs (default: false)\r\n- `ITS_BLOCK_LOCALHOST` - Block localhost access (default: true)\r\n- `ITS_REQUEST_TIMEOUT` - Network timeout in seconds (default: 10)\r\n- `ITS_DOMAIN_ALLOWLIST` - Comma-separated allowed domains\r\n\r\n**Schema Allowlist:**\r\n\r\n- `ITS_INTERACTIVE_ALLOWLIST` - Enable interactive prompts (default: true)\r\n- `ITS_ALLOWLIST_FILE` - Custom allowlist file location\r\n\r\n**Processing Limits:**\r\n\r\n- `ITS_MAX_TEMPLATE_SIZE` - Max template size in bytes (default: 1MB)\r\n- `ITS_MAX_CONTENT_ELEMENTS` - Max content elements (default: 1000)\r\n\r\n**Feature Toggles:**\r\n\r\n- `ITS_DISABLE_ALLOWLIST` - Disable schema allowlist\r\n- `ITS_DISABLE_INPUT_VALIDATION` - Disable input validation\r\n\r\n### Allowlist Management\r\n\r\nWhen `ITS_INTERACTIVE_ALLOWLIST` is enabled, you'll be prompted for unknown schemas:\r\n\r\n```\r\nSCHEMA ALLOWLIST DECISION REQUIRED\r\nURL: https://example.com/schema.json\r\n\r\n1. Allow permanently (saved to allowlist)\r\n2. Allow for this session only\r\n3. Deny (compilation will fail)\r\n```\r\n\r\n### Configuration File\r\n\r\nCreate `.its-config.json`:\r\n\r\n```json\r\n{\r\n  \"security\": {\r\n    \"allowHttp\": false,\r\n    \"domainAllowlist\": [\"alexanderparker.github.io\"],\r\n    \"maxSchemaSize\": \"10MB\"\r\n  },\r\n  \"compiler\": {\r\n    \"strictMode\": true,\r\n    \"reportOverrides\": true\r\n  }\r\n}\r\n```\r\n\r\n## Error Handling\r\n\r\nThe compiler provides detailed error messages:\r\n\r\n### Schema Validation Errors\r\n\r\n```\r\nITSValidationError: Template validation failed at content[2].config:\r\n  - Missing required property 'description'\r\n  - Invalid instruction type 'unknown_type'\r\n```\r\n\r\n### Variable Resolution Errors\r\n\r\n```\r\nITSVariableError: Undefined variable reference at content[1].config.description:\r\n  - Variable '${productName}' is not defined\r\n  - Available variables: productType, featureCount\r\n```\r\n\r\n## Testing\r\n\r\n```bash\r\n# Run all tests\r\npython test_runner.py\r\n\r\n# Run specific categories\r\npython test_runner.py --category security\r\npython test_runner.py --category integration\r\n\r\n# Run with verbose output\r\npython test_runner.py --verbose\r\n\r\n# Run linting and security checks\r\npython test_runner.py --lint\r\npython test_runner.py --security-scan\r\n```\r\n\r\n## API Reference\r\n\r\n### Required Imports\r\n\r\n```python\r\nfrom typing import Optional\r\nfrom its_compiler import ITSCompiler, ITSConfig\r\nfrom its_compiler.security import SecurityConfig\r\nfrom its_compiler.core.exceptions import ITSValidationError, ITSCompilationError\r\n```\r\n\r\n### ITSCompiler Class\r\n\r\n```python\r\nclass ITSCompiler:\r\n    def __init__(self, config: Optional[ITSConfig] = None,\r\n                 security_config: Optional[SecurityConfig] = None)\r\n\r\n    def compile(self, template: dict, variables: Optional[dict] = None,\r\n                base_url: Optional[str] = None) -> CompilationResult\r\n\r\n    def compile_file(self, template_path: str, variables: Optional[dict] = None) -> CompilationResult\r\n\r\n    def validate(self, template: dict, base_url: Optional[str] = None) -> ValidationResult\r\n\r\n    def validate_file(self, template_path: str) -> ValidationResult\r\n\r\n    def get_security_status(self) -> dict\r\n```\r\n\r\n### CompilationResult Class\r\n\r\n```python\r\nclass CompilationResult:\r\n    prompt: str                           # The compiled prompt\r\n    template: dict                        # The original template\r\n    variables: dict                       # Resolved variables\r\n    overrides: List[TypeOverride]         # Type overrides that occurred\r\n    warnings: List[str]                   # Compilation warnings\r\n    security_metrics: SecurityMetrics     # Security operation metrics\r\n    compilation_time: Optional[float]     # Time taken to compile\r\n    security_events: List[str]            # Security events that occurred\r\n\r\n    # Properties\r\n    @property\r\n    def has_overrides(self) -> bool       # Check if any type overrides occurred\r\n\r\n    @property\r\n    def has_warnings(self) -> bool        # Check if any warnings were generated\r\n\r\n    @property\r\n    def has_security_events(self) -> bool # Check if any security events occurred\r\n\r\n    @property\r\n    def prompt_size(self) -> int          # Get prompt size in bytes\r\n\r\n    # Methods\r\n    def get_summary(self) -> dict         # Get compilation summary with metrics\r\n```\r\n\r\n### ValidationResult Class\r\n\r\n```python\r\nclass ValidationResult:\r\n    is_valid: bool                        # Whether validation passed\r\n    errors: List[str]                     # Validation errors found\r\n    warnings: List[str]                   # Validation warnings\r\n    security_issues: List[str]            # Security issues found\r\n    validation_time: Optional[float]      # Time taken to validate\r\n\r\n    # Properties\r\n    @property\r\n    def has_security_issues(self) -> bool # Check if security issues were found\r\n\r\n    @property\r\n    def total_issues(self) -> int         # Get total count of all issues\r\n\r\n    def __bool__(self) -> bool            # Allows `if validation_result:` usage\r\n```\r\n\r\n## Contributing\r\n\r\n1. Fork the repository\r\n2. Create a feature branch (`git checkout -b feature/amazing-feature`; other branch prefixes could be used i.e. `bugfix`, `devops`, `test`, etc, depending on use-case)\r\n3. Make your changes and add / update tests, precommit configs, and github workflows as appropriate\r\n4. Ensure all tests pass (`python test_runner.py --all`)\r\n5. Commit your changes\r\n6. Push to the branch and ensure all github workflows pass\r\n7. Open a Pull Request\r\n\r\n### Development Setup\r\n\r\n```bash\r\n# Clone and setup\r\ngit clone https://github.com/AlexanderParker/its-compiler-python.git\r\ncd its-compiler-python\r\n\r\n# Create and activate virtual environment\r\npython -m venv venv\r\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\r\n\r\n# Install in development mode\r\npip install -e \".[dev]\"\r\n\r\n# Run tests\r\npython test_runner.py\r\n```\r\n\r\n### For Maintainers\r\n\r\n**Publishing to PyPI:**\r\n\r\nThis package is published to PyPI as `its-compiler`. Releases are currently managed manually:\r\n\r\n```bash\r\n# Build the package\r\npython -m build\r\n\r\n# Test upload to TestPyPI first (recommended)\r\npython -m twine upload --repository testpypi dist/*\r\n\r\n# Upload to production PyPI (requires appropriate credentials)\r\npython -m twine upload dist/*\r\n```\r\n\r\n**TestPyPI Testing:**\r\n\r\n```bash\r\n# Install from TestPyPI to verify the package\r\npip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ its-compiler\r\n```\r\n\r\n## Related Projects\r\n\r\n- **[ITS Compiler CLI](https://github.com/AlexanderParker/its-compiler-cli-python)** - Command-line interface for the ITS Compiler\r\n- **[Instruction Template Specification](https://alexanderparker.github.io/instruction-template-specification/)** - The official ITS specification and schema\r\n- **[ITS Example Templates](https://github.com/AlexanderParker/its-example-templates)** - Test templates and examples for the ITS compiler\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Reference Python library for Instruction Template Specification (ITS) with comprehensive security features",
    "version": "1.0.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/AlexanderParker/its-compiler-python/issues",
        "Changelog": "https://github.com/AlexanderParker/its-compiler-python/commits/main/",
        "Documentation": "https://github.com/AlexanderParker/its-compiler-python",
        "Homepage": "https://github.com/AlexanderParker/its-compiler-python",
        "Repository": "https://github.com/AlexanderParker/its-compiler-python.git"
    },
    "split_keywords": [
        "its",
        " instruction",
        " template",
        " specification",
        " ai",
        " prompt",
        " compilation",
        " nlp",
        " content-generation",
        " security",
        " library"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "840a00fc88fa160f9fad0bbf8cf8fbe5c5f3375f7106954cfd4d29a43155fc00",
                "md5": "319c51c71de418bf0e01ac930ec3636a",
                "sha256": "65475de3604dc173864f03bd1ac7bbd0c31cf3473e51f6d1ab8ba0936a6a12f4"
            },
            "downloads": -1,
            "filename": "its_compiler-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "319c51c71de418bf0e01ac930ec3636a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 50819,
            "upload_time": "2025-07-21T17:33:59",
            "upload_time_iso_8601": "2025-07-21T17:33:59.755442Z",
            "url": "https://files.pythonhosted.org/packages/84/0a/00fc88fa160f9fad0bbf8cf8fbe5c5f3375f7106954cfd4d29a43155fc00/its_compiler-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a8c5628660fdc7476c604bbd5d4fb48d916fe44d95216f4b1cbe3e30120f67c4",
                "md5": "920b897a1f18ef3429b3a34956e52ac4",
                "sha256": "3095bb7f2bddb57abf852be99f0ea814968b19916532724f6183b4f2b23a7a8c"
            },
            "downloads": -1,
            "filename": "its_compiler-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "920b897a1f18ef3429b3a34956e52ac4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 49629,
            "upload_time": "2025-07-21T17:34:01",
            "upload_time_iso_8601": "2025-07-21T17:34:01.434414Z",
            "url": "https://files.pythonhosted.org/packages/a8/c5/628660fdc7476c604bbd5d4fb48d916fe44d95216f4b1cbe3e30120f67c4/its_compiler-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-21 17:34:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlexanderParker",
    "github_project": "its-compiler-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "its-compiler"
}
        
Elapsed time: 1.13468s