Skip to main content

A library for creating, and working with models that may have incomplete information.

Project description

Wanting is a library for creating, and working with models that may have incomplete information.

Motivation

Instances of domain models don’t always spring into existence fully formed. They may be partially constructed intially, then filled in over time. Making a model field optional that is not intially available, but eventually required is inaccurate because an optional field may always be optional, so it never has to be filled in. It would be better to make the field a required union of the type it wants, and a placholder type. The wanting types are such placeholders. They can include metadata, such as the source of the update with missing data, and even partial data from that source.

Usage

A domain model may look like this:

from typing import Literal

import wanting
import pydantic

class User(pydantic.BaseModel):
    name: str
    employee_id: str | wanting.Unavailable
    department_code: Literal["TECH", "FO", "BO", "HR"] | wanting.Unmapped

Then there is an onboarding system that creates a User. However, the employee_id is unavailable at this time because it will be generated later. The onboarding system sources the department code from some other system, which uses different values than those in the User model. The onboarding system knows how to map some of the codes from the other system to the User department codes, but not all of them. However, because employee_id, and department_code may also be wanting fields in the User model, the onboarding system can still create a fully valid model, while also indicating that some information is missing:

user = User(
    name="Charlotte",
    employee_id=wanting.Unavailable(source="onboarding"),
    department_code=wanting.Unmapped(source="onboarding", value="art"),
)

The model validates, and all the wanting fields serialize to valid JSON:

assert user.model_dump() == {
    "name": "Charlotte",
    "employee_id": {
        "kind": "unavailable",
        "source": "onboarding",
        "value": b"null",
    },
    "department_code": {
        "kind": "unmapped",
        "source": "onboarding",
        "value": b'"art"',
    },
}

This user can now be persisted, then queried, and updated later by other systems.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wanting-0.3.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wanting-0.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file wanting-0.3.0.tar.gz.

File metadata

  • Download URL: wanting-0.3.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for wanting-0.3.0.tar.gz
Algorithm Hash digest
SHA256 518585873228d552e85b4c674fb9cc57989f5ad58129d9984597a72f36f086f2
MD5 0b8ff5a7cee2fd010fc2bb0e30a14108
BLAKE2b-256 65c55978c9ea46de1ebffdb2db7d8710d295838f86d82003df751f5e06c1cf67

See more details on using hashes here.

File details

Details for the file wanting-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: wanting-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for wanting-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ffe7b33dc02d826c4c106fe0272b7f566bf8c476bdc20e6bde4a57f0ead8b36
MD5 fd58c14b42e3e47dc4594d2e7b6ef222
BLAKE2b-256 2b1d9267a622de95bf3d07635c34c945ba7f758717036ee1dd56d949aa25bba4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page