A lightweight Python package inspired by RPGLE LIKE keyword for cloning field templates
Project description
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
pip install cloneit
Quick Start
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
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
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
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
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloneit-0.1.0.tar.gz.
File metadata
- Download URL: cloneit-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6af30cd700ed031fbef29cbfb6926881cadf1b0e9fd05c8c6eba85861c234c5
|
|
| MD5 |
21604ca195cdc0f673649d558aa130cd
|
|
| BLAKE2b-256 |
9b0d39c1e683a7001b47acf3abc6f2a1b093cfdfce376d1403de716dc1a6db39
|
File details
Details for the file cloneit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cloneit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63414d94a7f426c3d824dbb1b5515439d3f72f72278d9023fc00c03b6e71d04c
|
|
| MD5 |
f71b3d71bcd086f2139e269ad1950ad0
|
|
| BLAKE2b-256 |
a8af60d0207506f4a290f96b319170a09d3c6121fb19e2bb68773d72a0ee5433
|