API Reference
cwtch.cwtch
is_cwtch_model(cls) -> bool
is_cwtch_view(cls) -> bool
field(default: Any = _MISSING, *, default_factory: _Missing[Callable] = _MISSING, init: bool = True, init_alias: Unset[str] = UNSET, repr: Unset[Literal[False]] = UNSET, compare: Unset[bool] = UNSET, property: Unset[Literal[True]] = UNSET, validate: Unset[bool] = UNSET, metadata: Unset[dict] = UNSET, kw_only: Unset[dict] = UNSET) -> Any
Return an object to identify dataclass fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
Any
|
The default value of the field. |
_MISSING
|
default_factory
|
_Missing[Callable]
|
A 0-argument function called to initialize a field's value. |
_MISSING
|
init
|
bool
|
If init is true, the field will be a parameter to the class's |
True
|
repr
|
Unset[Literal[False]]
|
If repr is true, the field will be included in the object's repr(). |
UNSET
|
compare
|
Unset[bool]
|
If compare is true, the field will be used in comparison functions. |
UNSET
|
property
|
Unset[Literal[True]]
|
|
UNSET
|
validate
|
Unset[bool]
|
|
UNSET
|
metadata
|
Unset[dict]
|
If specified, must be a mapping which is stored but not otherwise examined by dataclass. |
UNSET
|
kw_only
|
Unset[dict]
|
If kw_only true, the field will become a keyword-only parameter to |
UNSET
|
It is an error to specify both default and default_factory.
Source code in cwtch/cwtch.py
dataclass(cls=None, *, slots: Unset[bool] = UNSET, kw_only: Unset[bool] = UNSET, env_prefix: Unset[str | Sequence[str]] = UNSET, env_source: Unset[Callable] = UNSET, validate: Unset[bool] = UNSET, add_disable_validation_to_init: Unset[bool] = UNSET, show_input_value_on_error: Unset[bool] = UNSET, extra: Unset[Literal['ignore', 'forbid']] = UNSET, repr: Unset[bool] = UNSET, eq: Unset[bool] = UNSET, recursive: Unset[bool | Sequence[str]] = UNSET, handle_circular_refs: Unset[bool] = UNSET) -> Callable[[Type[T]], Type[T]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slots
|
Unset[bool]
|
If true, |
UNSET
|
kw_only
|
Unset[bool]
|
If kw_only is true, then by default all fields are keyword-only. |
UNSET
|
env_prefix
|
Unset[str | Sequence[str]]
|
Prefix(or list of prefixes) for environment variables. |
UNSET
|
env_source
|
Unset[Callable]
|
Environment variables source factory. By default os.environ. |
UNSET
|
validate
|
Unset[bool]
|
Validate or not fields. |
UNSET
|
add_disable_validation_to_init
|
Unset[bool]
|
Add disable_validation keywoard argument to |
UNSET
|
extra
|
Unset[Literal['ignore', 'forbid']]
|
Ignore or forbid extra arguments passed to init. |
UNSET
|
repr
|
Unset[bool]
|
If true, a |
UNSET
|
eq
|
Unset[bool]
|
If true, an |
UNSET
|
recursive
|
Unset[bool | Sequence[str]]
|
... |
UNSET
|
handle_circular_refs
|
Unset[bool]
|
Handle or not circular refs. |
UNSET
|
Source code in cwtch/cwtch.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
view(base_cls, name: Unset[str] = UNSET, *, attach: Unset[bool] = UNSET, include: Unset[Sequence[str]] = UNSET, exclude: Unset[Sequence[str]] = UNSET, slots: Unset[bool] = UNSET, kw_only: Unset[bool] = UNSET, env_prefix: Unset[str | Sequence[str]] = UNSET, env_source: Unset[Callable] = UNSET, validate: Unset[bool] = UNSET, add_disable_validation_to_init: Unset[bool] = UNSET, extra: Unset[Literal['ignore', 'forbid']] = UNSET, repr: Unset[bool] = UNSET, eq: Unset[bool] = UNSET, recursive: Unset[bool | Sequence[str]] = UNSET, handle_circular_refs: Unset[bool] = UNSET) -> Callable[[Type[T]], Type[T]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Unset[str]
|
View name. |
UNSET
|
attach
|
Unset[bool]
|
If true, view will be attached to base cls. |
UNSET
|
include
|
Unset[Sequence[str]]
|
List of fields to include in view. |
UNSET
|
exclude
|
Unset[Sequence[str]]
|
List of fields to exclude from view. |
UNSET
|
slots
|
Unset[bool]
|
If true, |
UNSET
|
kw_only
|
Unset[bool]
|
If kw_only is true, then by default all fields are keyword-only. |
UNSET
|
env_prefix
|
Unset[str | Sequence[str]]
|
Prefix(or list of prefixes) for environment variables. If UNSET value from base view model will be used. |
UNSET
|
env_source
|
Unset[Callable]
|
Environment variables source factory. If UNSET value from base view model will be used. |
UNSET
|
validate
|
Unset[bool]
|
Validate or not fields. If UNSET value from base view model will be used. |
UNSET
|
add_disable_validation_to_init
|
Unset[bool]
|
Add disable_validation keywoard argument to |
UNSET
|
extra
|
Unset[Literal['ignore', 'forbid']]
|
Ignore or forbid extra arguments passed to init. If UNSET value from base view model will be used. |
UNSET
|
repr
|
Unset[bool]
|
If true, a |
UNSET
|
eq
|
Unset[bool]
|
If true, an |
UNSET
|
recursive
|
Unset[bool | Sequence[str]]
|
... |
UNSET
|
handle_circular_refs
|
Unset[bool]
|
Handle or not circular refs. If UNSET value from base view model will be used. |
UNSET
|
Source code in cwtch/cwtch.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
from_attributes(cls, obj: Any, data: dict | None = None, exclude: Sequence | None = None, suffix: str | None = None, reset_circular_refs: bool | None = None)
Build model from attributes of other object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Object from which to build. |
required |
data
|
dict | None
|
Additional data to build. |
None
|
exclude
|
Sequence | None
|
List of fields to exclude. |
None
|
suffix
|
str | None
|
Fields suffix. |
None
|
reset_circular_refs
|
bool | None
|
Reset circular references to None. |
None
|
Source code in cwtch/cwtch.py
asdict(inst, include: Sequence[str] | None = None, exclude: Sequence[str] | None = None, exclude_none: bool | None = None, exclude_unset: bool | None = None, context: dict | None = None) -> dict
Return cwtch model as dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst
|
cwtch model. |
required | |
include
|
Sequence[str] | None
|
List of field names to include. |
None
|
exclude
|
Sequence[str] | None
|
List of field names to exclude. |
None
|
exclude_none
|
bool | None
|
If true, fields with None value will be excluded. |
None
|
exclude_unset
|
bool | None
|
If true, unset fields will be excluded. |
None
|
context
|
dict | None
|
If specified, must be a mapping. |
None
|
Source code in cwtch/cwtch.py
dumps_json(inst, encoder: Callable[[Any], Any] | None = None, context: dict | None = None)
Dump cwtch model to json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoder
|
Callable[[Any], Any] | None
|
Custom JSON encoder as callable. |
None
|
context
|
dict | None
|
If specified, must be a mapping. |
None
|
Source code in cwtch/cwtch.py
validate_args(fn: Callable, args: tuple, kwds: dict) -> tuple[tuple, dict]
Helper to convert and validate function arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
tuple
|
function positional arguments. |
required |
kwds
|
dict
|
function keyword arguments. |
required |
Source code in cwtch/cwtch.py
validate_call(fn)
Decorator to convert and validate function arguments.