https://github.com/aweirddev/exacting
exacting is a picky dataclass runtime utility collection, making sure all type annotations are followed.
https://github.com/aweirddev/exacting
python-data-structures python-dataclass-type-validator python-dataclasses
Last synced: 3 months ago
JSON representation
exacting is a picky dataclass runtime utility collection, making sure all type annotations are followed.
- Host: GitHub
- URL: https://github.com/aweirddev/exacting
- Owner: AWeirdDev
- License: mit
- Created: 2025-06-24T14:43:05.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-06-29T06:00:38.000Z (4 months ago)
- Last Synced: 2025-07-31T00:11:17.965Z (3 months ago)
- Topics: python-data-structures, python-dataclass-type-validator, python-dataclasses
- Language: Python
- Homepage: https://aweirddev.github.io/exacting/
- Size: 699 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Exacting
> *(adj.) making great demands on one's skill, attention, or other resources.*
โ
[**Docs**](https://aweirddev.github.io/exacting) and [**PyPi**](https://pypi.org/project/exacting)
`exacting` is a picky dataclass runtime utility collection, making sure all type annotations are followed.
Essentially... **THE** go-to option for dataclasses. heh.
**๐ Key features**:
- **100% static typing.** Because I hate nothing too.
- Generally **faster** than [`pydantic`](https://pydantic.dev)!

## Quick tour
This won't take you long :)
**๐๏ธ Get `exacting`**:
```haskell
pip install -U exacting
```
**๐ฅ Define some model**:
(Let's just say you're on Python 3.10+... good boy!)
```python
from exacting import Exact
class Actor(Exact):
name: str
portrays: str
class Show(Exact):
name: str
description: str | None
actors: list[Actor]
```
Nawh... I'm on an older version
Oh, it's definitely okay! We got you covered ๐ฅ๐ฅ
```python
from typing import List, Optional
from exacting import Exact
class Actor(Exact):
name: str
portrays: str
class Show(Exact):
name: str
description: Optional[str]
actors: List[Actor]
```
**๐ฆ Build 'em**:
```python
# (1) โ
OK, exacting is happi
Show(
name="Severance",
description="great show",
actors=[
Actor(name="Adam Scott", portrays="Mark S."),
Actor(name="Britt Lower", portrays="Helly R."),
]
)
# (2) โ Nuh-uh, exacting is angri
Show(
name=123,
description=False,
actors=[
"Walter White",
"Jesse Pinkman"
]
)
```
๐ด ValidationError: During validation ofโฆ
```python
ValidationError:
During validation of dataclass Show at field 'name', got:
โข Expected type , got
```
Normally, when you use the parameters passed in example (2) above, the Python `dataclasses` library might as well just go with it, because they only put the additional **static typing** to the model, but not at **runtime**. Exacting makes sure that at both times, types are all enforced. It even gives you a detailed error message on where this occurs! (In a cool way)
It's worth noting that error generations are *lazy*, which means once Exacting finds out about a problem about a dataclass, it raises a `ValidationError`. This saves a lot of computation time if you have a larger model.

Yeah, we also got fields! Use it like how you'd expect it. Quite literally, lol.
```python
from exacting import Exact, field
def create_ai_slop():
return "tick tock"
class Comment(Exact):
user: str = field(regex="^@.+$")
stars: int = field(minv=1, maxv=5)
body: str = field(default_factory=create_ai_slop)
# โ
OK, exacting is HYPED
Comment(
user="@waltuh",
stars=5
)
# โ Hell nawh, exacting holdin' you at gunpoint
Comment(
user="ooga booga", # Regex validation '^@.+$' on str failed
stars=-1, # Expected min value of 1, got -1
body=None # Expected type , got
)
```
Woah! That's a lot of code to process. To put it simply, exacting supports:
- **Regex** validation on `str`
- **Min/max** validation on value (e.g., `int`, `float`) or length (e.g., `str`, `list`)
- **Default** values or factory! Y'know, the old `dataclasses` way, mmmMMM
- This is extra, but **custom** validation! You can make your own if you like

Kind of, but somehow native performance is way better than Rust. That is, exacting is *generally* faster than Pydantic on a few benchmarks. Woooosh
Anyway, thanks for sticking with us, you can [read the docs](https://aweirddev.github.io/exacting) if you'd like.