Metadata-Version: 2.4
Name: django-typescript-api
Version: 0.1.0rc1
Summary: Generate TypeScript clients from Django APIs
Author-email: Py Env Studio Team <contact.shaikh.wasim@gmail.com>
License: MIT License
        
        Copyright (c) 2025 pyenvstudio
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=4.0
Requires-Dist: Jinja2
Dynamic: license-file


# Django TypeScript API Generator

A zero-dependency Django plugin that automatically generates TypeScript interfaces and documentation from your Django models.

## Features

- **Zero Dependencies:** Uses only Django and Python standard libraries
- **Type-Safe Interfaces:** Generate TypeScript interfaces from Django models
- **Comprehensive Documentation:** Automatic JSDoc generation with field descriptions and validation rules
- **Validation Constraints:** Extracts min/max length, value constraints, regex patterns, and choices
- **Highly Configurable:** Customize through Django settings or command-line options
- **Scalable Architecture:** Built with design patterns for future extensibility


## Installation

Add to your `INSTALLED_APPS`:

```python
# settings.py
INSTALLED_APPS = [
    # ...
    'django_typescript_api',
]
```

Configure (optional):

```python
# settings.py
DJANGO_TYPESCRIPT_API = {
    'OUTPUT_PATH': 'frontend/src/api/generated.ts',
    'INCLUDE_DOCS': True,
    'INCLUDE_VALIDATORS': True,
    'TYPE_MAPPINGS': {
        'DecimalField': 'string',  # Override default mapping
    }
}
```


## Usage

```bash
# Generate TypeScript interfaces
python manage.py generate_ts_client

# Specific output file
python manage.py generate_ts_client --output frontend/src/api/models.ts

# Only specific apps
python manage.py generate_ts_client --apps blog users

# Skip documentation
python manage.py generate_ts_client --no-docs

# Skip validation constraints
python manage.py generate_ts_client --no-validators

# Verbose output with details
python manage.py generate_ts_client --verbose

# Dry run (preview without writing)
python manage.py generate_ts_client --dry-run
```


## Example Output

```typescript
// Generated by django-typescript-api
// DO NOT EDIT THIS FILE DIRECTLY

/**
 * Blog post
 * @interface Post
 */
export interface Post {
  /**
   * Post title
   * @minLength 5
   * @maxLength 200
   */
  title: string;
  
  /**
   * Publication status
   * @enum {'draft', 'published', 'archived'}
   */
  status: 'draft' | 'published' | 'archived';
  
  /**
   * When the post was created
   */
  created_at: string;
}

export interface User {
  // ... with similar documentation
}
```


## Supported Field Types

- String fields: `CharField`, `TextField`, `EmailField`, `SlugField`, etc.
- Numeric fields: `IntegerField`, `FloatField`, `DecimalField`, etc.
- Boolean fields: `BooleanField`
- Date/time fields: `DateField`, `DateTimeField`, `TimeField`
- Relations: `ForeignKey`, `OneToOneField`, `ManyToManyField`
- Special fields: `UUIDField`, `JSONField`, `FileField`


## Configuration Options

| Setting | Default | Description |
| :-- | :-- | :-- |
| OUTPUT_PATH | frontend/src/api/generated.ts | Output file path |
| INCLUDE_DOCS | True | Generate JSDoc documentation |
| INCLUDE_VALIDATORS | True | Include validation constraints |
| TYPE_MAPPINGS | {} | Custom Django-to-TypeScript type mappings |
| CUSTOM_HEADERS | Predefined | Custom file header comments |

## Roadmap

- Phase 2: API endpoint generation from DRF viewsets
- Phase 3: Query parameter typing and advanced features
- Phase 4: Performance optimizations and extensibility hooks


## Contributing

This is currently in active development. The architecture is designed with scalability in mind using Builder, Visitor, and Strategy patterns.

## License

MIT License – feel free to use and contribute!

***
