A collection of Value Objects to save time by generalizing data type and format validations.
Project description
Python Value-Objects
A collection of Value Objects to save time by generalizing types and format validations.
Value-objects
Numeric value-objects
Int
Integer numbers without a fractional component that don't support decimal points.
from pyvalueobjects import Int
# Creation
my_integer = Int(9)
# Getting raw value
my_integer.value() # returns -> 9
Nullable Int
Integer numbers and None.
from pyvalueobjects import NullableInt
# Creation
my_integer = NullableInt(9)
# Creating from None
my_nullable_integer = NullableInt(None)
# Getting raw value
my_integer.value() # returns -> 9
my_nullable_integer.value() # returns -> None
String value-objects
String
from pyvalueobjects import String
# Creation
my_str = String('potato')
# Getting raw value
my_str.value() # returns -> 'potato'
Nullable String
from pyvalueobjects import NullableString
# Creation
my_str = NullableString('potato')
# Getting raw value
my_str.value() # returns -> 'potato'
# Creation
my_nullable_str = NullableString(None)
# Getting raw value
my_nullable_str.value() # returns -> None
Non Empty String
from pyvalueobjects import NonEmptyString
# Creation
my_str = NonEmptyString('potato')
# Getting raw value
my_str.value() # returns -> 'potato'
# Creation
my_str2 = NonEmptyString('') # raises error
Nullable non Empty String
from pyvalueobjects import NullableNonEmptyString
# Creation
my_str = NullableNonEmptyString('potato')
# Getting raw value
my_str.value() # returns -> 'potato'
# Creation
my_str2 = NullableNonEmptyString(None)
# Getting raw value
my_str2.value() # returns -> None
# Creation
my_str3 = NullableNonEmptyString('') # raises error
Uuid4
from pyvalueobjects import Uuid4
# Creation
my_uuid4 = Uuid4('6c7add12-bf35-459e-a6c5-3178a2a33011')
# Getting raw value
my_uuid4.value() # returns -> '6c7add12-bf35-459e-a6c5-3178a2a33011'
Nullable Uuid4
from pyvalueobjects import NullableUuid4
# Creation
my_uuid4 = NullableUuid4('6c7add12-bf35-459e-a6c5-3178a2a33011')
my_null_uuid4 = NullableUuid4(None)
# Getting raw value
my_uuid4.value() # returns -> '6c7add12-bf35-459e-a6c5-3178a2a33011'
my_null_uuid4.value() # returns -> 'None'
Date value-objects
ISO Date
from pyvalueobjects import IsoDate
# Creation
my_date = IsoDate('2023-08-15T04:55:12.076Z')
# Getting raw value
my_date.value() # returns -> '2023-08-15T04:55:12.076Z'
Security value-objects
CVE
from pyvalueobjects import Cve
# Creation
my_cve = Cve('CVE-2014-9418')
# Getting raw value
my_cve.value() # returns -> 'CVE-2014-9418'
Nullable CVE
from pyvalueobjects import NullableCve
# Creation
my_cve = NullableCve('CVE-2014-9418')
my_null_cve = NullableCve(None)
# Getting raw value
my_cve.value() # returns -> 'CVE-2014-9418'
my_null_cve.value() # returns -> None
CPE
from pyvalueobjects import Cpe
# Creation
my_cpe = Cpe('cpe:/a:openjdk:openjdk:8u282')
# Getting raw value
my_cpe.value() # returns -> 'cpe:/a:openjdk:openjdk:8u282'
Nullable CPE
from pyvalueobjects import NullableCpe
# Creation
my_cpe = NullableCpe('cpe:/a:openjdk:openjdk:8u282')
my_null_cpe = NullableCpe(None)
# Getting raw value
my_cpe.value() # returns -> 'cpe:/a:openjdk:openjdk:8u282'
my_null_cpe.value() # returns -> None
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyvalueobjects-0.24.0.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for pyvalueobjects-0.24.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d199adbb59ac86d4da24f4c812fb58100635003bc3fa225c36d9e5e53c529df |
|
MD5 | 5c981543f37498694c4005d3160dc0e1 |
|
BLAKE2b-256 | fbd75e06fd5a6b3a3f971ad18242e5693a3d8372de26db064e455b15ed6970a3 |