{"id":28398270,"url":"https://github.com/nexios-labs/voltar","last_synced_at":"2025-06-28T14:31:35.965Z","repository":{"id":289972684,"uuid":"972996894","full_name":"nexios-labs/voltar","owner":"nexios-labs","description":"Sift Validator is a lightweight and expressive Python library for defining, parsing, and validating data structures with ease. Designed for clarity, speed, and full control.","archived":false,"fork":false,"pushed_at":"2025-05-04T04:21:18.000Z","size":370,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-01T13:15:17.698Z","etag":null,"topics":["asgi","async","nexios","nexios-api","voltar"],"latest_commit_sha":null,"homepage":"https://nexios-labs.gitbook.io/voltar","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nexios-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-26T03:31:48.000Z","updated_at":"2025-05-06T07:06:05.000Z","dependencies_parsed_at":"2025-04-27T01:20:35.341Z","dependency_job_id":"76b59956-fc43-4122-936a-75654f59e689","html_url":"https://github.com/nexios-labs/voltar","commit_stats":null,"previous_names":["nexios-labs/sift-validator","nexios-labs/voltar"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nexios-labs/voltar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexios-labs%2Fvoltar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexios-labs%2Fvoltar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexios-labs%2Fvoltar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexios-labs%2Fvoltar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nexios-labs","download_url":"https://codeload.github.com/nexios-labs/voltar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexios-labs%2Fvoltar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262444775,"owners_count":23312228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","async","nexios","nexios-api","voltar"],"created_at":"2025-06-01T04:38:01.603Z","updated_at":"2025-06-28T14:31:35.953Z","avatar_url":"https://github.com/nexios-labs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"./logo.svg\" alt=\"Voltar Logo\" width=\"200\" height=\"200\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"  \u003e\n\n# Voltar \n\n\u003c/p\u003e\n\nA modern Python validation library with Zod-like syntax, async support, and OpenAPI integration.\n\n## Features\n\n- 🔄 **Chainable API**: Intuitive, fluent interface for building validation schemas\n- ⚡ **Async Support**: Fast, non-blocking validation for high-performance applications\n- 📝 **Type Hints**: Comprehensive typing for excellent editor integration\n- 📊 **OpenAPI**: Seamless generation of OpenAPI schemas from your validators\n- 🔍 **Powerful Validation**: Built-in validators for common use cases with custom validation support\n- 🔧 **Data Transformation**: Transform and normalize data during validation\n\n## Installation\n\n```bash\npip install voltar \n```\n\n## Quick Start\n\n```python\nimport voltar as v\n\n# Define a schema\nuser_schema = v.Object({\n    \"username\": v.String().min(3).max(20).trim(),\n    \"email\": v.String().email(),\n    \"age\": v.Number().int().min(18).optional(),\n    \"tags\": v.List(v.String()).min(1).max(5),\n})\n\n# Validate data\ntry:\n    valid_user = user_schema.validate({\n        \"username\": \"  johndoe  \",  # Will be trimmed\n        \"email\": \"john@example.com\",\n        \"tags\": [\"python\", \"validation\"]\n    })\n    print(valid_user)\nexcept ValueError as e:\n    print(f\"Validation error: {e}\")\n\n# Async validation\nimport asyncio\n\nasync def validate_user_async():\n    try:\n        valid_user = await user_schema.validate_async({\n            \"username\": \"johndoe\",\n            \"email\": \"john@example.com\",\n            \"tags\": [\"python\", \"validation\"]\n        })\n        print(valid_user)\n    except ValueError as e:\n        print(f\"Validation error: {e}\")\n\nasyncio.run(validate_user_async())\n```\n\n## OpenAPI Integration\n\n```python\nimport voltar as v\nfrom voltar.openapi import generate_openapi_schema\n\nuser_schema = v.Object({\n    \"username\": v.String().min(3).max(20),\n    \"email\": v.String().email(),\n    \"age\": v.Number().int().min(18),\n})\n\n# Generate OpenAPI schema\nopenapi_schema = generate_openapi_schema(user_schema)\nprint(openapi_schema)\n```\n\n# Schema Modification\n\nVoltar provides powerful schema modification capabilities through three main methods: `extend`, `exclude`, and `omit`. These methods allow you to adapt and reuse schemas flexibly while maintaining type safety and validation rules.\n\n## Extending Schemas (`extend`)\n\nUse `extend` to add new fields to an existing schema without modifying the original:\n\n```python\nimport voltar as v\n\n# Base user schema\nuser_schema = v.Object({\n    \"name\": v.String(),\n    \"age\": v.Number()\n})\n\n# Create employee schema by extending user schema\nemployee_schema = user_schema.extend({\n    \"department\": v.String(),\n    \"salary\": v.Number()\n})\n\n# Base schema remains unchanged\nuser_data = user_schema.validate({\n    \"name\": \"John\",\n    \"age\": 30\n})\n\n# Extended schema includes all fields\nemployee_data = employee_schema.validate({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"department\": \"Engineering\",\n    \"salary\": 75000\n})\n```\n\n## Excluding Fields (`exclude`)\n\nUse `exclude` to temporarily ignore specific fields during validation. The fields remain in the schema but aren't validated:\n\n```python\nimport voltar as v\n\n# Schema with sensitive data\nuser_schema = v.Object({\n    \"name\": v.String(),\n    \"age\": v.Number(),\n    \"email\": v.Email(),\n    \"ssn\": v.String()\n})\n\n# Create public view that doesn't validate sensitive fields\npublic_schema = user_schema.exclude(\"email\", \"ssn\")\n\n# These fields are allowed but not validated\npublic_schema.validate({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"email\": \"not-validated\",  # Would normally fail Email validation\n    \"ssn\": \"any-value\"        # No validation performed\n})\n```\n\n## Omitting Fields (`omit`)\n\nUse `omit` to create a new schema without specific fields. Unlike `exclude`, omitted fields are not allowed in the data:\n\n```python\nimport voltar as v\n\n# Full user schema\nuser_schema = v.Object({\n    \"name\": v.String(),\n    \"age\": v.Number(),\n    \"email\": v.Email(),\n    \"password\": v.String()\n})\n\n# Create public profile schema without sensitive data\nprofile_schema = user_schema.omit([\"password\", \"email\"])\n\n# Valid: only includes allowed fields\nprofile_schema.validate({\n    \"name\": \"John\",\n    \"age\": 30\n})\n\n# Invalid: raises ValidationError for omitted fields\nprofile_schema.validate({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"password\": \"secret\"  # Error: unexpected field\n})\n```\n\n## Key Differences: `exclude` vs `omit`\n\n- `exclude`:\n  - Fields remain in schema but are ignored during validation\n  - Excluded fields can still be present in the data\n  - Useful for temporary validation skipping or partial validation\n  - Validation rules remain for non-excluded fields\n\n- `omit`:\n  - Creates new schema without specified fields\n  - Omitted fields are not allowed in the data\n  - Useful for creating permanent subsets of schemas\n  - Validates against unexpected fields\n\n## Combining Operations\n\nYou can chain or combine these operations for more complex schema modifications:\n\n```python\nimport voltar as v\n\n# Start with comprehensive schema\nfull_schema = v.Object({\n    \"name\": v.String(),\n    \"age\": v.Number(),\n    \"email\": v.Email(),\n    \"password\": v.String(),\n    \"preferences\": v.Object({\n        \"theme\": v.String(),\n        \"notifications\": v.Boolean()\n    })\n})\n\n# Create public profile schema:\n# 1. Omit sensitive fields\n# 2. Extend with additional fields\n# 3. Exclude validation for specific fields\npublic_profile = (\n    full_schema\n    .omit([\"password\", \"email\"])  # Remove sensitive fields\n    .extend({\n        \"avatar\": v.String(),\n        \"bio\": v.String()\n    })  # Add public profile fields\n    .exclude(\"preferences\")  # Don't validate preferences\n)\n\n# Usage:\nprofile = public_profile.validate({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"avatar\": \"https://example.com/avatar.jpg\",\n    \"bio\": \"Software developer\",\n    \"preferences\": {\"invalid\": \"structure\"}  # Allowed but not validated\n})\n```\n\n## Common Use Cases\n\n1. **API Response Schemas**\n   ```python\n   import voltar as v\n   \n   # Internal schema with all fields\n   internal = v.Object({\n       \"id\": v.Number(),\n       \"name\": v.String(),\n       \"email\": v.Email(),\n       \"created_at\": v.DateTime(),\n       \"internal_notes\": v.String()\n   })\n\n   # Public API response schema\n   api_response = internal.omit([\"internal_notes\"])\n   ```\n\n2. **Form Validation**\n   ```python\n   import voltar as v\n   \n   # Complete user schema\n   user = v.Object({\n       \"username\": v.String(),\n       \"email\": v.Email(),\n       \"password\": v.String(),\n       \"confirm_password\": v.String()\n   })\n\n   # Schema for profile update form (no password fields)\n   profile_update = user.omit([\"password\", \"confirm_password\"])\n   ```\n\n3. **Role-Based Schemas**\n   ```python\n   import voltar as v\n   \n   # Base product schema\n   product = v.Object({\n       \"id\": v.Number(),\n       \"name\": v.String(),\n       \"price\": v.Number(),\n       \"cost\": v.Number(),\n       \"supplier_id\": v.String()\n   })\n\n   # Customer view (omit internal fields)\n   customer_view = product.omit([\"cost\", \"supplier_id\"])\n\n   # Sale view (exclude validation for internal calculations)\n   sale_view = product.exclude(\"cost\")\n   ```\n\n## Tips and Best Practices\n\n1. Use `extend` when you need to add new fields while keeping existing ones\n\n2. Use `exclude` when:\n   - Fields should remain in the data but not be validated\n   - Validation skipping is temporary\n   - You need to preserve the field in the output\n\n3. Use `omit` when:\n   - Fields should not be present in the data\n   - You're creating a permanent subset of a schema\n   - You want to enforce field absence\n\n4. When combining operations, consider the order:\n   - `extend` then `omit` to remove fields from the complete schema\n   - `omit` then `extend` to add new fields to a reduced schema\n   - `exclude` can be used at any point to skip validation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexios-labs%2Fvoltar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnexios-labs%2Fvoltar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexios-labs%2Fvoltar/lists"}