Skip to main content

Librery to use it in a simple way to do a cast of an array to Literal[], to use it for validation with Pydantic

Project description

To_literal

Is a micro librery to use it with pydantic, we can do now convert Literal[] to simple array in python, or reverse in a simple way.

Repository: Static Badge

Why i do it?

I'm still doing a RestAPI with FastAPI with React Native, and when you need to obtain from your database with nosql an array, you can't convert in the simplest way array to Literal[] and you can't validate data in a flexible way. To save before data an after apply to your new values to use it, from your database to validate with Pydantic.

How to use it

from pydantic import BaseModel
from to_literal.v1 import toLiteral

hoursL = toLiteral([
    '9:00',
    '9:30',
])

class testLiteral(BaseModel):
    hours: hoursL


#   Good Example:

test = testLiteral(hours='9:30')
print(test.model_dump())

#   Result:
#   { 
#       'hours': '9:30'
#   }



#   Bad Example -> ERROR:

test = testLiteral(hours='10:30')
print(test.model_dump())

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

to_literal-1.1.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

to_literal-1.1.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file to_literal-1.1.2.tar.gz.

File metadata

  • Download URL: to_literal-1.1.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.0

File hashes

Hashes for to_literal-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ddaf09a521ecd57e08903bf3d3822d3ddd0e5394b76146730dd6c0bc7a60ba1e
MD5 de4a576855b0d7732bc22a958e755301
BLAKE2b-256 7e22c7436035e371770608a146fdd3e12ade54924365b2b4151ff87415e472ce

See more details on using hashes here.

File details

Details for the file to_literal-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: to_literal-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.0

File hashes

Hashes for to_literal-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be8fb53524c8889b49139d1bc65f4d5b54319b4cceecff4698c3c599cb59479b
MD5 4d7979a8b854cd8db25b69ea44c4f2ea
BLAKE2b-256 11416129b5dc9b5375332128e82cc6cee3d6ffc7843a3f3d78f813d393e19b1d

See more details on using hashes here.

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