Convert Polars or Pandas DataFrames to lists of Pydantic models with schema inference
Project description
❄️ Articuno ❄️
Convert Polars or Pandas DataFrames to Pydantic models with schema inference — and generate clean Python class code.
✨ Features
- Infer Pydantic models dynamically from Polars or Pandas DataFrames
- Support for nested structs, optional fields, and common data types
- Generate clean Python model code using datamodel-code-generator
- Lightweight, dependency-flexible design
📦 Installation
Install the core package:
pip install articuno
Add optional dependencies as needed:
-
Polars support:
pip install articuno[polars]
-
Pandas support:
pip install articuno[pandas]
Or install all extras:
pip install articuno[polars,pandas]
🚀 Usage
🔍 Infer a Pydantic model from a DataFrame
from articuno import df_to_pydantic
import polars as pl
df = pl.DataFrame({
"id": [1, 2, 3],
"name": ["Alice", "Bob", "Charlie"],
"score": [95.5, 88.0, 92.3]
})
models = df_to_pydantic(df)
print(models[0])
Output:
id=1 name='Alice' score=95.5
You can also infer a model class without creating instances:
from articuno.models import infer_pydantic_model
Model = infer_pydantic_model(df, model_name="MyModel")
print(Model.schema_json(indent=2))
Output (abbreviated):
{
"title": "MyModel",
"type": "object",
"properties": {
"id": { "title": "Id", "type": "integer" },
"name": { "title": "Name", "type": "string" },
"score": { "title": "Score", "type": "number" }
},
"required": ["id", "name", "score"]
}
🧾 Generate Python class code from a Pydantic model
from articuno.codegen import generate_class_code
code = generate_class_code(Model)
print(code)
Output (example):
from pydantic import BaseModel
class AutoPolarsModel(BaseModel):
id: int
name: str
score: float
📜 Patito vs Articuno
| Feature | 🦜 Patito | ❄️ Articuno |
|---|---|---|
| Polars–Pydantic bridge | ✅ Declarative schema | ✅ Dynamic inference |
| Validation constraints | ✅ Unique, bounds | ⚠️ Basic types, nullables |
| Nested Structs | ❌ Not supported | ✅ Fully recursive |
| Code generation | ❌ | ✅ via datamodel-code-gen |
| Example/mock data | ✅ .examples |
❌ |
| Direct Pandas/Polars support | ❌ Indirect via dicts | ✅ Native support with inference |
Patito is ideal for static schema validation with custom constraints and ETL pipelines.
Articuno excels at dynamic schema inference, nested model generation, and code export for API use cases.
⚙️ Supported Type Mappings
| Polars Type | Pandas Type | Pydantic Type |
|---|---|---|
pl.Int*, pl.UInt* |
int64, int32, Int64 (nullable int) |
int |
pl.Float* |
float64, float32 |
float |
pl.Utf8 |
object (string) |
str |
pl.Boolean |
bool, boolean (nullable bool) |
bool |
pl.Date |
datetime64[ns] (date only) |
datetime.date |
pl.Datetime |
datetime64[ns] (timestamp) |
datetime.datetime |
pl.Duration |
timedelta64[ns] |
datetime.timedelta |
pl.List |
list, object with lists |
List[...] |
pl.Struct |
dict, object with nested dicts |
Nested Pydantic model |
pl.Null |
NaN, None (nullable fields) |
Optional[...] |
🛠️ Development
To install development dependencies:
pip install articuno[dev]
Run tests with:
pytest
🔗 Links
📄 License
MIT © Odos Matthews
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file articuno-0.6.1.tar.gz.
File metadata
- Download URL: articuno-0.6.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee18a04ac491c965362f82c137bf23d468a02cf3a86fbdf521aac80364f8c571
|
|
| MD5 |
1db3ffdba3544a36d108ef6e10a29429
|
|
| BLAKE2b-256 |
bac316fdc09bd50db5dc514cdd9f39cf7226f9f0f84fb0230393b389b53617e6
|
File details
Details for the file articuno-0.6.1-py3-none-any.whl.
File metadata
- Download URL: articuno-0.6.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c750ccba60bb4777a858f718ed4834ad6e9d76200d697bdc3e8de0a096cfd10
|
|
| MD5 |
93f5137d458f35f465af4a940fad2725
|
|
| BLAKE2b-256 |
b661bdc177d10f93b176a135347f66ca5d95d3d881cbacf7c53e6c4898baf541
|