Metadata-Version: 2.4
Name: midjargon
Version: 1.2.8
Project-URL: Documentation, https://github.com/twardoch/midjargon#readme
Project-URL: Issues, https://github.com/twardoch/midjargon/issues
Project-URL: Source, https://github.com/twardoch/midjargon
Author-email: Adam Twardoch <adam+github@twardoch.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.10
Requires-Dist: pydantic>=2.0.0
Provides-Extra: all
Requires-Dist: mypy>=1.0.0; extra == 'all'
Requires-Dist: pre-commit>=3.6.0; extra == 'all'
Requires-Dist: pytest-cov>=4.0.0; extra == 'all'
Requires-Dist: pytest>=7.0.0; extra == 'all'
Requires-Dist: ruff>=0.1.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: pre-commit>=3.6.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# Midjargon

`midjargon` is a Python library for parsing and manipulating Midjourney prompts using a specialized syntax. This tool helps you work with Midjourney prompts in a structured way, handling complex features like permutations, parameter validation, and image URL extraction.

## Features

- **Robust Prompt Parsing**: 
  - Parse Midjourney prompts into structured components (text, parameters, image URLs)
  - Type-safe parsing with comprehensive validation
  - Support for complex prompt structures and syntax

- **Advanced Permutation Support**: 
  - Handle nested permutations in curly braces `{option1, option2}`
  - Support for escaped characters in permutations (e.g., `\,` for literal commas)
  - Combine permutations across text and parameters
  - Automatic expansion of all possible combinations

- **Comprehensive Parameter Handling**:
  - Validate parameter names and values
  - Support for numeric ranges (stylize, chaos, weird, etc.)
  - Handle aspect ratios and style parameters
  - Process boolean flags and multi-value parameters
  - Proper type conversion and validation

- **Image URL Processing**:
  - Extract and validate image URLs
  - Support for multiple image inputs
  - Validate file extensions and URL formats
  - Handle image weights and reference images

- **Multi-prompt Support**:
  - Handle weighted prompts using `::`
  - Process multiple variations in a single input
  - Support for negative weights and prompt mixing

- **Type Safety**:
  - Full type hints throughout the codebase
  - Pydantic models for robust validation
  - Clear error messages for invalid inputs
  - Modern Python type annotations

- **Rich CLI Interface**:
  - Beautiful console output with syntax highlighting
  - JSON output option for automation
  - Support for raw parsing and full validation
  - Helpful error messages and formatting

## Installation

```bash
pip install midjargon
```

## Quick Start

### Basic Usage

```python
from midjargon import parse_midjourney_dict, expand_midjargon_input

# Parse a simple prompt
prompt = "a serene landscape --ar 16:9 --stylize 100"
result = expand_midjargon_input(prompt)[0]
validated = parse_midjourney_dict(result)

# Work with permutations
prompt_with_perms = "a {red, blue} bird on a {flower, leaf} --ar 16:9"
variations = expand_midjargon_input(prompt_with_perms)
for variation in variations:
    parsed = parse_midjourney_dict(variation)
    print(parsed.text)  # Prints each combination

# Complex prompt with images and weights
complex_prompt = """
https://example.com/image.jpg 
mystical forest ::2 foggy mountains ::1 
--chaos 20 --stylize 100
"""
parsed = parse_midjourney_dict(complex_prompt)
```

### CLI Usage

```bash
# Basic prompt parsing
midjargon "a photo of a cat --ar 16:9"

# Get JSON output
midjargon --json-output "a photo of a cat --ar 16:9"

# Raw parsing without validation
midjargon --raw "any text with parameters"

# Parse prompt with permutations
midjargon "a {red, blue} bird --stylize {100, 500}"
```

## Project Structure

```
midjargon/
├── src/midjargon/
│   ├── core/           # Core parsing functionality
│   ├── engines/        # Engine-specific implementations
│   └── cli/            # Command-line interface
├── tests/              # Test suite
├── SPEC.md            # Format specification
└── CODE.md            # Code documentation
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Some ways to contribute:

- Bug fixes and feature improvements
- Documentation updates
- Additional test cases
- Performance optimizations
- New engine implementations
- CLI enhancements

### Development Setup

1. Clone the repository
2. Install development dependencies:
   ```bash
   uv pip install --system --upgrade ".[all]"
   ```
3. Run tests:
   ```bash
   python -m pytest
   ```
   or 
    ```bash
   python -m pytest
   ```

4. Format code:
   ```bash
   ruff check --fix --unsafe-fixes . && ruff format --respect-gitignore --target-version py312 .
   ```

## License

MIT License - See LICENSE file for details 