# Phenopackets v2 Quickstart

## Installation

```bash
pip install "ai4gh[phenopackets]"
```

## Create a Phenopacket

```python
from ai4gh.specs.phenopackets.models import (
    Disease,
    Individual,
    OntologyClass,
    Phenopacket,
    PhenotypicFeature,
)

# Build a clinical phenopacket
phenopacket = Phenopacket(
    id="patient-001",
    subject=Individual(
        id="P001",
        sex="FEMALE",
        date_of_birth="1990-01-15",
    ),
    phenotypic_features=[
        PhenotypicFeature(
            type=OntologyClass(id="HP:0001250", label="Seizure"),
        ),
        PhenotypicFeature(
            type=OntologyClass(id="HP:0001263", label="Global developmental delay"),
        ),
    ],
    diseases=[
        Disease(
            term=OntologyClass(id="OMIM:618285", label="DEE68"),
        ),
    ],
)

# Serialize to JSON
print(phenopacket.model_dump_json(indent=2))
```

## Validate a Phenopacket

```python
import json
from ai4gh.specs.phenopackets.models import Phenopacket

# Parse and validate
data = json.loads(phenopacket_json)
validated = Phenopacket.model_validate(data)
print(f"Valid phenopacket: {validated.id}")
```

## MCP Tool

```json
{
  "tool": "phenopacket_validate",
  "arguments": {
    "phenopacket_json": "{\"id\": \"P001\", \"subject\": {\"id\": \"S001\"}}"
  }
}
```

## Data Models

```python
from ai4gh.specs.phenopackets.models import (
    Phenopacket,
    Family,
    Cohort,
    Individual,
    PhenotypicFeature,
    Disease,
    MedicalAction,
    Measurement,
    Biosample,
    OntologyClass,
    GeneDescriptor,
    VariantInterpretation,
)
```
