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.

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.1.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

to_literal-1.1.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: to_literal-1.1.1.tar.gz
  • Upload date:
  • Size: 2.3 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.1.tar.gz
Algorithm Hash digest
SHA256 ccd229f829edfaf3838eac99f4c5d64f21ec99d65907b370c3050739d0ff21b9
MD5 b5ca8dac2f2acd7b177eed9415b5018e
BLAKE2b-256 41d90bbaa9e315605d4dcac4cb98032e3f4949fd1e7de4bcca9f2e6a4d2e9dcb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: to_literal-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b27a4ad8e7cfdb8ddf25ab5b3fa48b71d0c6850a7a8f786a32893e67f19249e5
MD5 4328862eb8d72469e5cfd6f025c41a27
BLAKE2b-256 6df95ce3f41698010808601a0c1c866130fcaeae7e330dfb86dc8867344cf00f

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