klotz: pydantic*

0 bookmark(s) - Sort by: Date ↓ / Title / - Bookmarks from other users for this tag

  1. This article explores ten underrated Python libraries that can help automate tasks, debug faster, and improve coding efficiency.

    • Rich: Terminal beautification
    • PyWhatKit: Automation tasks
    • Pydantic: Data validation
    • Black: Code formatting
    • HTTPie: API testing
    • Typer: Building CLI applications
    • IceCream: Debugging
    • Poetry: Package management
    • Faker: Generating fake data
    • Pyppeteer: Browser automation
  2. An analysis showing that structured outputs can sometimes perform worse than unstructured ones in certain tasks for different LLM models, emphasizing the importance of testing both approaches.

    2024-12-12 Tags: , , , by klotz
  3. main.py

    import json from pydantic import BaseModel, EmailStr, ValidationError, validator

    class Employee(BaseModel): name: str age: int email: EmailStr department: str employee_id: str

    @validator("employee_id")
     def validate_employee_id(cls, v):
         if not v.isalnum() or len(v) != 6:
             raise ValueError("Employee ID must be exactly 6 alphanumeric characters")
         return v
    

    Load and parse the JSON data

    with open("employees.json", "r") as f: data = json.load(f)

    Validate each employee record

    for record in data: try: employee = Employee(**record) print(f"Valid employee record: {employee.name}") except ValidationError as e: print(f"Invalid employee record: {record 'name' » }") print(f"Errors: {e.errors()}"

    2024-03-26 Tags: , , by klotz

Top of the page

First / Previous / Next / Last / Page 1 of 0 SemanticScuttle - klotz.me: Tags: pydantic

About - Propulsed by SemanticScuttle