██╗███╗ ██╗████████╗███████╗ ██████╗ ██████╗ ██╗██╗ ██╗███╗ ███╗
██║████╗ ██║╚══██╔══╝██╔════╝██╔════╝ ██╔══██╗██║██║ ██║████╗ ████║
██║██╔██╗ ██║ ██║ █████╗ ██║ ███╗██████╔╝██║██║ ██║██╔████╔██║
██║██║╚██╗██║ ██║ ██╔══╝ ██║ ██║██╔══██╗██║██║ ██║██║╚██╔╝██║
██║██║ ╚████║ ██║ ███████╗╚██████╔╝██║ ██║██║╚██████╔╝██║ ╚═╝ ██║
╚═╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝
🔐 Advanced Data Validation Framework 🔐
The Integrity Element - Where Data Meets Trust
Quick Start • Features • Examples • Documentation
🌟 What is INTEGRIUM?
INTEGRIUM is a modern, powerful data validation framework that goes beyond simple schema validation. It's built on Pydantic but adds intelligent sanitization, custom validators, and a developer-friendly API that makes data integrity effortless.
from integrium import Validator, Field, sanitize
class User(Validator):
name: str = Field(min_length=2, max_length=50)
email: str = Field(pattern=r'^[\w\.-]+@[\w\.-]+\.\w+$')
age: int = Field(ge=0, le=150)
user = User(name=" John Doe ", email="john@example.com", age=30)
# ✅ Automatically validated and sanitized!
✨ Key Features
📦 Installation
# Basic installation
pip install integrium
# With email validation
pip install integrium[email]
# With all features
pip install integrium[all]
🎯 Quick Start
Basic Validation
from integrium import Validator
class Product(Validator):
name: str
price: float
quantity: int
# Valid data
product = Product(name="Laptop", price=999.99, quantity=10)
print(product.name) # "Laptop"
# Invalid data raises ValidationError
try:
Product(name="", price=-10, quantity="invalid")
except ValidationError as e:
print(e.errors())
With Advanced Constraints
from integrium import Validator, Field
from pydantic import EmailStr
class UserProfile(Validator):
username: str = Field(
min_length=3,
max_length=20,
pattern=r'^[a-zA-Z0-9_]+$'
)
email: EmailStr
age: int = Field(ge=13, le=120)
bio: str = Field(max_length=500, default="")
profile = UserProfile(
username="john_doe",
email="john@example.com",
age=25,
bio="Python developer"
)
Smart Sanitization
from integrium import sanitize
# String cleaning
text = sanitize(" Hello World ") # "hello world"
# Email normalization
email = sanitize("John.Doe@EXAMPLE.COM", mode="email") # "john.doe@example.com"
# URL cleaning
url = sanitize(" https://example.com/page ", mode="url") # "https://example.com/page"
🏗️ Architecture
graph LR
A[Raw Data] --> B[INTEGRIUM]
B --> C{Validation}
B --> D{Sanitization}
C --> E[Pydantic Core]
D --> F[Custom Rules]
E --> G[Type Checking]
E --> H[Constraints]
F --> I[String Clean]
F --> J[XSS Filter]
G --> K[Validated Data]
H --> K
I --> K
J --> K
K --> L[Your Application]
style B fill:#9C27B0
style K fill:#4CAF50
🔥 Advanced Features
Custom Validators
from integrium import Validator, field_validator
class Account(Validator):
username: str
password: str
@field_validator('password')
@classmethod
def validate_password(cls, v):
if len(v) < 8:
raise ValueError('Password must be at least 8 characters')
if not any(c.isupper() for c in v):
raise ValueError('Password must contain uppercase letter')
if not any(c.isdigit() for c in v):
raise ValueError('Password must contain digit')
return v
Nested Validation
from integrium import Validator
from typing import List
class Address(Validator):
street: str
city: str
country: str
postal_code: str
class Company(Validator):
name: str
employees: int
addresses: List[Address]
company = Company(
name="Tech Corp",
employees=100,
addresses=[
{"street": "123 Main St", "city": "NYC", "country": "USA", "postal_code": "10001"},
{"street": "456 Park Ave", "city": "LA", "country": "USA", "postal_code": "90001"}
]
)
Schema Decorator
from integrium import schema
@schema
class APIResponse:
status: str
data: dict
message: str = "Success"
# Use as a validator
response = APIResponse(status="ok", data={"user_id": 123})
📊 Comparison with Other Libraries
| Feature | INTEGRIUM | Pydantic | Cerberus | Marshmallow | Voluptuous |
|---|---|---|---|---|---|
| Type Hints | ✅ Full | ✅ Full | ❌ No | ⚠️ Partial | ❌ No |
| Sanitization | ✅ Built-in | ❌ Manual | ⚠️ Limited | ⚠️ Limited | ❌ No |
| Async Support | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No |
| Error Messages | ✅ Rich | ✅ Good | ⚠️ Basic | ✅ Good | ⚠️ Basic |
| Performance | ⚡⚡⚡⚡ | ⚡⚡⚡⚡⚡ | ⚡⚡⚡ | ⚡⚡ | ⚡⚡⚡ |
| Learning Curve | 🟢 Easy | 🟢 Easy | 🟡 Medium | 🟡 Medium | 🟢 Easy |
🎨 Real-World Examples
API Request Validation
from integrium import Validator, Field
from fastapi import FastAPI, HTTPException
app = FastAPI()
class CreateUserRequest(Validator):
username: str = Field(min_length=3, max_length=20)
email: EmailStr
password: str = Field(min_length=8)
@app.post("/users")
async def create_user(request: CreateUserRequest):
# Data is already validated!
return {"message": "User created", "username": request.username}
Form Data Cleaning
from integrium import sanitize
def clean_form_data(form):
return {
"name": sanitize(form.get("name", "")),
"email": sanitize(form.get("email", ""), mode="email"),
"message": sanitize(form.get("message", ""), mode="xss")
}
Database Model Validation
from integrium import Validator
from datetime import datetime
class DBUser(Validator):
id: int
username: str
email: str
created_at: datetime
is_active: bool = True
class Config:
from_attributes = True # Allow ORM models
# Use with SQLAlchemy, Django, etc.
user = DBUser.from_orm(db_user_object)
📚 Documentation
🗺️ Roadmap
✅ Version 0.1.0 (Current)
- Pydantic integration
- Basic sanitization
- Field validation
- Custom validators
🚧 Version 0.2.0 (Coming Soon)
- Async validation
- i18n error messages
- JSON Schema export
- More sanitization modes
🔮 Version 0.3.0 (Planned)
- GraphQL schema generation
- OpenAPI integration
- Validation caching
- Performance optimizations
🤝 Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
📜 License
MIT License - see LICENSE file for details.
👤 Author
Release files for integrium 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| integrium-0.2.0.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| integrium-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.6 kB
Release files / integrium-0.2.0.tar.gz
| Download URL | integrium-0.2.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97357581789bb98d7f318f0cb7c889dcc3ef9adaf708f6683ceb8c01acd359cc
|
|
BLAKE2b-256 checksum How to use checksums |
2e07dc48605f78c8911d1d3f27e253f00b1d44160748d8a61d6da2b44e07943e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Release files / integrium-0.2.0-py3-none-any.whl
| Download URL | integrium-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9db41353cf81fc60cab55db4c974d116dfc53cb47c56c8ae5cc222950e6416fa
|
|
BLAKE2b-256 checksum How to use checksums |
f966a631d765ed0009e3f05fb9c9598b7c3316fa465b02e75a4f879fa6e1ce4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|