Skip to main content

Changes the data-type in a json or dictionary using Pydantic Basemodel.

Project description

Data-Type Caster

This project aim is to convert the given json or dictionary format structure to same structure with values of desired data-type, Which is achived using Pydantic Basemodel.

Installation

PIP

pip install type-changer

Usage

from pydantic import BaseModel
from type_changer import Caster

class model(BaseModel):
    a:str
    b:int
    c:list[str]

input = {"a":"hello", "b":"45327", "c":[34,45,56]}

ct = Caster(model, input)
out = ct.cast()
print(out)

Note:

  • This project consider your input is a valid json or dictionary.
  • Create a Basemodel class for every dict in the json or dictionary.
  • This project supports only the following data-types which are 'str', 'int', 'float', 'list', 'tuple' and 'bool'.

License

This project is licensed under AGPL-3 license and 'All rights Reserved'. For more details see the LICENSE file.

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

type_changer-0.0.2.tar.gz (15.2 kB view hashes)

Uploaded Source

Built Distribution

type_changer-0.0.2-py3-none-any.whl (16.3 kB view hashes)

Uploaded Python 3

Supported by

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