project.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Pydantic schemas for Project API.
  3. Defines request and response models for project operations.
  4. """
  5. from datetime import datetime
  6. from typing import Optional
  7. from pydantic import BaseModel, Field
  8. class ProjectCreate(BaseModel):
  9. """Schema for creating a new project."""
  10. name: str = Field(..., min_length=1, description="Project name")
  11. description: str = Field(default="", description="Project description")
  12. config: str = Field(..., min_length=1, description="Label Studio configuration")
  13. class Config:
  14. json_schema_extra = {
  15. "example": {
  16. "name": "Image Classification Project",
  17. "description": "Classify images into categories",
  18. "config": "<View><Image name='image' value='$image'/><Choices name='choice' toName='image'><Choice value='Cat'/><Choice value='Dog'/></Choices></View>"
  19. }
  20. }
  21. class ProjectUpdate(BaseModel):
  22. """Schema for updating an existing project."""
  23. name: Optional[str] = Field(None, min_length=1, description="Project name")
  24. description: Optional[str] = Field(None, description="Project description")
  25. config: Optional[str] = Field(None, min_length=1, description="Label Studio configuration")
  26. class Config:
  27. json_schema_extra = {
  28. "example": {
  29. "name": "Updated Project Name",
  30. "description": "Updated description"
  31. }
  32. }
  33. class ProjectResponse(BaseModel):
  34. """Schema for project response."""
  35. id: str = Field(..., description="Project unique identifier")
  36. name: str = Field(..., description="Project name")
  37. description: str = Field(..., description="Project description")
  38. config: str = Field(..., description="Label Studio configuration")
  39. created_at: datetime = Field(..., description="Project creation timestamp")
  40. task_count: int = Field(default=0, description="Number of tasks in project")
  41. class Config:
  42. json_schema_extra = {
  43. "example": {
  44. "id": "proj_123abc",
  45. "name": "Image Classification Project",
  46. "description": "Classify images into categories",
  47. "config": "<View><Image name='image' value='$image'/></View>",
  48. "created_at": "2024-01-12T10:30:00",
  49. "task_count": 5
  50. }
  51. }