cloneit 0.1.0
A lightweight Python package inspired by RPGLE LIKE keyword for cloning field templates
Requires Python: >=3.6
Keywords: field, template, clone, rpgle, like, data, model, schema, django, pydantic, marshmallow, validation, boilerplate

# cloneit

A lightweight Python package inspired by the RPGLE LIKE keyword, designed to simplify and standardize field definitions by allowing developers to clone reusable field templates across projects.

## Features

- 🔄 **Field Template Registration**: Register field templates with reusable attributes
- 📋 **Field Cloning**: Create new fields by cloning existing templates  
- ⚙️ **Field Overrides**: Modify attributes while cloning (e.g., default, required)
- ✅ **Validation Support**: Ensure required template exists; raise exceptions otherwise
- 🔌 **Easy Integration**: Can be used in any Python data class, model, or schema
- 📦 **Framework Agnostic**: Works with Django, Pydantic, Marshmallow, and more

## Installation

```bash
pip install cloneit
```

## Quick Start

```python
from cloneit import FieldTemplate, Field

# Register field templates
FieldTemplate.register('email', {
    'type': str,
    'required': True,
    'max_length': 255,
    'validation': 'email'
})

FieldTemplate.register('name', {
    'type': str,
    'required': True,
    'max_length': 100,
    'min_length': 2
})

# Clone fields with LIKE-style syntax
user_email = Field.like('email')
admin_email = Field.like('email', required=False, default='admin@company.com')
first_name = Field.like('name')
last_name = Field.like('name', max_length=150)
```

## Usage Examples

### With Pydantic Models

```python
from pydantic import BaseModel
from cloneit import FieldTemplate, Field

# Register common field templates
FieldTemplate.register('id_field', {
    'type': int,
    'required': True,
    'gt': 0
})

FieldTemplate.register('timestamp', {
    'type': datetime,
    'required': True,
    'default_factory': datetime.now
})

class User(BaseModel):
    id: int = Field.like('id_field')
    email: str = Field.like('email')
    name: str = Field.like('name')
    created_at: datetime = Field.like('timestamp')
```

### With Django Models

```python
from django.db import models
from cloneit import FieldTemplate, Field

# Register Django-specific templates
FieldTemplate.register('django_email', {
    'field_class': models.EmailField,
    'max_length': 255,
    'unique': True
})

FieldTemplate.register('django_name', {
    'field_class': models.CharField,
    'max_length': 100,
    'blank': False
})

class User(models.Model):
    email = Field.like('django_email')
    first_name = Field.like('django_name')
    last_name = Field.like('django_name', max_length=150)
```

### With Marshmallow Schemas

```python
from marshmallow import Schema, fields
from cloneit import FieldTemplate, Field

# Register Marshmallow field templates
FieldTemplate.register('marshmallow_email', {
    'field_class': fields.Email,
    'required': True,
    'validate': lambda x: '@' in x
})

class UserSchema(Schema):
    email = Field.like('marshmallow_email')
    name = Field.like('marshmallow_name')
```

## API Reference

### FieldTemplate

#### `FieldTemplate.register(name: str, attributes: dict)`
Register a field template with the given name and attributes.

#### `FieldTemplate.get(name: str) -> dict`
Get a registered field template by name.

#### `FieldTemplate.exists(name: str) -> bool`
Check if a field template exists.

#### `FieldTemplate.list() -> list`
List all registered field template names.

### Field

#### `Field.like(template_name: str, **overrides) -> Any`
Clone a field template with optional attribute overrides.

## Error Handling

```python
from cloneit import FieldTemplate, Field, TemplateNotFoundError

try:
    field = Field.like('nonexistent_template')
except TemplateNotFoundError as e:
    print(f"Template not found: {e}")
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Inspired By

This package is inspired by the RPGLE LIKE keyword, providing a familiar tool for developers transitioning from AS/400 or RPGLE to Python.