Skip to content

Conversation

@dbrattli
Copy link
Collaborator

@dbrattli dbrattli commented Dec 3, 2025

Add Pydantic v2 support for Fable-Python numeric types and arrays. Pydantic is the most widely used data validation library for Python. We do not really want to add special support for 3rd party libraries in Fable, but Pydantic is special, and reducing the friction of using Fable with Pydantic without taking a direct dependency on Pydantic is an acceptable tradeoff imo.

Implements get_pydantic_core_schema for all Fable-Python core types, enabling seamless integration with
Pydantic models.

Changes:

  • Add Pydantic schema support to integer types (Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64) in
    ints.rs
  • Add Pydantic schema support to float types (Float32, Float64) in floats.rs
  • Add Pydantic schema support to FSharpArray in array.rs
  • Add F# tests for Pydantic models with core types

Usage:

from fable_library.core import int32, float64, Array
from pydantic import BaseModel

class User(BaseModel):
    age: int32
    score: float64
    tags: Array

user = User(age=30, score=95.5, tags=["a", "b"])
user.model_dump_json()  # {"age":30,"score":95.5,"tags":["a","b"]}

@dbrattli dbrattli merged commit 52d9915 into main Dec 3, 2025
22 checks passed
@dbrattli dbrattli deleted the numberic-serialization branch December 3, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants