Getting Started

Getting Started

Quick introduction to Tyck

Tyck is a TypeScript-inspired validation library for Python that provides a fluent, chainable API for defining validation schemas. Built on top of Pydantic, it offers a more concise and expressive syntax while maintaining full compatibility with the Pydantic ecosystem. Key features include: - Fluent method chaining for readable schema definitions - Full Pydantic v2 compatibility - TypeScript-like utility functions (pick, omit, partial, extend) - Zero learning curve for Pydantic users - Complete type inference and IDE support

Example

example.py
from tyck import interface, string, number, integer, array, optional
  
  # Define a User schema with validation constraints
  User = interface({
      'id': integer.positive(),
      'username': string.min(3).max(20).pattern(r'^[a-zA-Z0-9_]+$'),
      'email': string.email(),
      'age': optional(integer.range(13, 120)),
      'roles': array(string).min(1).default(['user']),
      'profile': optional(interface({
          'bio': string.max(500),
          'website': optional(string.url()),
          'social_links': array(string.url()).max(5)
      }))
  })
  
  # Create and validate a user instance
  user = User(
      id=1,
      username="john_doe",
      email="john@example.com",
      age=28,
      profile={
          'bio': "Software developer passionate about Python",
          'website': "https://johndoe.dev",
          'social_links': ["https://github.com/johndoe"]
      }
  )
  
  # Serialize to dictionary or JSON
  print(user.model_dump())
  print(user.model_dump_json(indent=2))
  
  # Access fields with full type hints
  print(f"Welcome, {user.username}!")
  print(f"Roles: {', '.join(user.roles)}")