Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Automatically generate two versions of your pydantic models: one with Extra.forbid and one with Extra.ignore
Automatically and lazily generate three versions of your pydantic models: one with Extra.forbid, one with Extra.ignore, and one with all fields optional
pip install pydantic-duality
Given the following models:
from pydantic_duality import DualBaseModel
class User(DualBaseModel):
id: UUID
name: str
class Auth(DualBaseModel):
some_field: str
user: User
Using pydantic-duality is roughly equivalent to making all of the following models by hand:
from pydantic import BaseModel
# Equivalent to User and User.__request__
class UserRequest(BaseModel, extra=Extra.forbid):
id: UUID
name: str
# Rougly equivalent to Auth and Auth.__request__
class AuthRequest(BaseModel, extra=Extra.forbid):
some_field: str
user: UserRequest
# Rougly equivalent to User.__response__
class UserResponse(BaseModel, extra=Extra.ignore):
id: UUID
name: str
# Rougly equivalent to Auth.__response__
class AuthResponse(BaseModel, extra=Extra.ignore):
some_field: str
user: UserResponse
# Rougly equivalent to User.__patch_request__
class UserPatchRequest(BaseModel, extra=Extra.forbid):
id: UUID | None
name: str | None
# Rougly equivalent to Auth.__patch_request__
class AuthPatchRequest(BaseModel, extra=Extra.forbid):
some_field: str | None
user: UserPatchRequest | None
So it takes you up to 3 times less code to write the same thing. Note also that pydantic-duality does everything lazily so you will not notice any significant performance or memory usage difference when using it instead of writing everything by hand. Think of it as using all the customized models as cached properties.
Inheritance, inner models, custom configs, custom names, config kwargs, isinstance and subclass checks work intuitively and in the same manner as they would work if you were not using pydantic-duality.
See documentation for more details
FAQs
Automatically generate two versions of your pydantic models: one with Extra.forbid and one with Extra.ignore
We found that pydantic-duality demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.