Skip to main content

typewriter_python/
lib.rs

1//! # typewriter-python
2//!
3//! Python Pydantic v2 / dataclass emitter for the typewriter type sync SDK.
4//! Generates `.py` files with Pydantic `BaseModel` classes.
5//!
6//! ## Type Mappings
7//!
8//! | Rust Type | Python Type |
9//! |-----------|-------------|
10//! | `String` | `str` |
11//! | `bool` | `bool` |
12//! | `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64` | `int` |
13//! | `f32`, `f64` | `float` |
14//! | `Uuid` | `UUID` |
15//! | `DateTime<Utc>` | `datetime` |
16//! | `Option<T>` | `Optional[T] = None` |
17//! | `Vec<T>` | `list[T]` |
18//! | `HashMap<K, V>` | `dict[K, V]` |
19//! | Custom struct/enum | Class reference |
20//!
21//! ## Configuration
22//!
23//! In `typewriter.toml`:
24//!
25//! ```toml
26//! [python]
27//! output_dir = "./generated/python"
28//! file_style = "snake_case"   # snake_case (default), kebab-case, or PascalCase
29//! pydantic_v2 = true          # Use Pydantic v2 (default: true)
30//! use_dataclass = false       # Use @dataclass instead of BaseModel
31//! ```
32//!
33//! ## Example
34//!
35//! **Rust Input:**
36//! ```rust,ignore
37//! #[derive(TypeWriter)]
38//! #[sync_to(python)]
39//! pub struct User {
40//!     pub id: String,
41//!     pub email: String,
42//!     pub age: Option<u32>,
43//! }
44//! ```
45//!
46//! **Generated Python:**
47//! ```python
48//! from pydantic import BaseModel
49//! from typing import Optional
50//!
51//!
52//! class User(BaseModel):
53//!     id: str
54//!     email: str
55//!     age: Optional[int] = None
56//! ```
57
58mod emitter;
59mod mapper;
60
61pub use mapper::PythonMapper;