| Crates.io | facet-python |
| lib.rs | facet-python |
| version | 0.43.2 |
| created_at | 2026-01-22 16:54:28.557305+00 |
| updated_at | 2026-01-23 18:06:40.74262+00 |
| description | Generate Python type definitions from facet type metadata |
| homepage | https://facet.rs |
| repository | https://github.com/facet-rs/facet |
| max_upload_size | |
| id | 2062165 |
| size | 57,348 |
Generate Python type definitions from facet type metadata.
This crate uses facet's reflection capabilities to generate Python type hints
and TypedDicts from any Rust type that implements Facet. This enables
type-safe interop when your Rust code exchanges data with Python.
use facet::Facet;
use facet_python::to_python;
#[derive(Facet)]
struct User {
name: String,
age: u32,
email: Option<String>,
}
let python_code = to_python::<User>(false);
This generates:
from typing import TypedDict, Required, NotRequired
class User(TypedDict, total=False):
name: Required[str]
age: Required[int]
email: str # Optional fields become NotRequired
| Rust Type | Python Type |
|---|---|
String, &str |
str |
i32, u32, etc. |
int |
f32, f64 |
float |
bool |
bool |
Vec<T> |
list[T] |
Option<T> |
T (NotRequired in TypedDict) |
HashMap<K, V> |
dict[K, V] |
| Struct | TypedDict |
| Enum | Union[...] of variants |
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
The facet logo was drawn by Misiasart.
Licensed under either of:
at your option.