Metadata-Version: 2.4
Name: tsc-py
Version: 0.1.2
Summary: A TypeSpec parser that generates Python dataclasses
Author-email: Arun Sharma <arun@sharma-home.net>
License-Expression: MIT
Project-URL: Homepage, https://github.com/adsharma/tsc-py
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: dataclasses; python_version < "3.7"
Requires-Dist: jinja2>=3.1.6
Requires-Dist: parsimonious>=0.10.0
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"

# TypeSpec Parser for Python

A Python library that parses TypeSpec definitions and generates Python dataclasses.

## Features

- Parse TypeSpec model definitions
- Generate Python dataclasses with type hints
- Support for enums
- Support for 1:1 and 1:n relationships
- Command-line interface

## Installation

### Using uv

```bash
uv pip install tsc-py
```

### Running without installing

```bash
uvx tsc-py schema.tsp
```

## Usage

### Command Line

```bash
# Parse a TypeSpec file and output to stdout
typespec-parser schema.tsp

# Parse a TypeSpec file and save to a Python file
typespec-parser schema.tsp -o models.py
```

### Python API

```python
from typespec_parser import TypeSpecParser

parser = TypeSpecParser()
parser.parse("""
model User {
  name: string;
  age: integer;
  email: string?;
}

enum Status {
  active,
  inactive,
}
""")

# Generate Python dataclasses
code = parser.generate_dataclasses()
print(code)
```

## Example

Given the following TypeSpec:

```typespec
model User {
  name: string;
  age: integer;
  email: string?;
  addresses: Address[];
}

model Address {
  street: string;
  city: string;
  country: string;
}

enum Status {
  active,
  inactive,
}
```

The parser will generate:

```python
from dataclasses import dataclass
from typing import List, Optional
from enum import Enum

class Status(Enum):
    ACTIVE = 'active'
    INACTIVE = 'inactive'

@dataclass
class Address:
    street: str
    city: str
    country: str

@dataclass
class User:
    name: str
    age: int
    email: Optional[str]
    addresses: List[Address]
```

## Development

This project uses `uv` for dependency management and packaging.

To install dependencies and set up the development environment:

```bash
uv sync --dev
```

To run tests:

```bash
uv run pytest
```

## License

MIT
