validate-with-resolute
Immutable object modifications with the Result pattern, inspired by C# records.
Wraps dataclass and Pydantic model construction/modification in resolute so validation errors are returned, never raised.
Installation
pip install validate-with-resolute
Requires Python 3.13+.
Usage
Record base class (recommended)
Inherit from Record to get .from_() and .with_() with full type checking and IDE autocomplete.
from dataclasses import dataclass
from validate_with_resolute import Record
@dataclass
class User(Record):
name: str
age: int
# Safe construction
result = User.from_(name="Bob", age=25)
if result.is_success:
user = result.value
# Safe modification — original unchanged
result = user.with_(name="Alice", age=30)
if result.is_success:
print(result.value.name) # "Alice"
print(user.name) # "Bob"
Works with Pydantic:
from pydantic import BaseModel, field_validator
from validate_with_resolute import Record
class User(BaseModel, Record):
name: str
age: int
@field_validator('age')
@classmethod
def validate_age(cls, v: int) -> int:
if v < 0:
raise ValueError('age must be positive')
return v
result = User.from_(name="Bob", age=-5)
if result.has_errors:
print(result.errors) # validation errors captured, not raised
user = User(name="Bob", age=25)
result = user.with_(age=-5) # same — errors captured
modify() standalone function
No inheritance required:
from dataclasses import dataclass
from validate_with_resolute import modify
@dataclass
class User:
name: str
age: int
user = User(name="Bob", age=25)
result = modify(user, name="Alice", age=30)
if result.is_success:
print(result.value.name) # "Alice"
@with_modify decorator
Adds .with_() to an existing class without inheritance. Type checkers require # type: ignore[attr-defined] on call sites.
from validate_with_resolute import with_modify
@with_modify
@dataclass
class User:
name: str
age: int
result = user.with_(name="Alice") # type: ignore[attr-defined]
Prefer Record or modify() instead.
Result API
All functions return Resolute[T] from the resolute package:
result.is_success # True on success
result.has_errors # True on failure
result.value # Modified object (success only)
result.errors # List of captured errors (failure only)
Supported types
| Type | Strategy |
|---|---|
| Pydantic v2 model | model_validate |
| Dataclass | dataclasses.replace |
| Other (Python 3.13+) | copy.replace() |
| Unsupported | TypeError in result.errors |
Type checking
The package ships a py.typed marker and full generic annotations. result.value is typed as T.
| Approach | mypy | Autocomplete |
|---|---|---|
Record base class |
full | full |
modify() function |
full | full |
@with_modify decorator |
needs ignore | none |
Nested objects
new_address = modify(address, city="LA").value
result = modify(person, address=new_address)
License
MIT
Metadata
Release files for validate-with-resolute 0.9.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| validate_with_resolute-0.9.2.tar.gz | 13.4 kB | Without provenance | Details for validate_with_resolute-0.9.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| validate_with_resolute-0.9.2-py3-none-any.whl | Python 3 | none | any | Details for validate_with_resolute-0.9.2-py3-none-any.whl |
Total release size: 22.3 kB
Release files / validate_with_resolute-0.9.2.tar.gz
| Download URL | validate_with_resolute-0.9.2.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02836e26c0a691c173a72c8c6914b25dec33b1a95a9a21bc135586ce5a528f39
|
|
BLAKE2b-256 checksum How to use checksums |
69f52066e105c59516b7b12c0a54efbfba0601e24b87ba960c8df91300d9d2d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / validate_with_resolute-0.9.2-py3-none-any.whl
| Download URL | validate_with_resolute-0.9.2-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb5c3136de1aaf682967684c200ffb9da5faabb86528ca50a14d031066345559
|
|
BLAKE2b-256 checksum How to use checksums |
7dd62875476cebbb4b5ed8b45ba2ade11d756cbc4e59e22d782a2f36d00e113a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for validate-with-resolute 0.9.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.