Skip to content

n1nj4t4nuk1/python-value-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Š Python Value Objects

GitHub Pypi Downloads GA

Β 

A collection of Value Objects to save time by generalizing types and format validations.

Value-objects

Numeric value-objects

Int

A basic integer value object that ensures the value is a valid integer without decimal points. It provides type safety and validation for integer values.

from pyvalueobjects import Int

# Creation
my_integer = Int(9)

# Getting raw value
my_integer.value() # returns -> 9

Nullable Int

An integer value object that can also be None, useful for optional numeric fields. It provides the same validation as Int but allows for null values.

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

Positive Int

An integer value object that ensures the value is strictly greater than zero. Useful for representing quantities, counts, or any value that must be positive.

from pyvalueobjects import PositiveInt

# Creation
my_integer = PositiveInt(9)

# Getting raw value
my_integer.value() # returns -> 9

Nullable Positive Int

A positive integer value object that can also be None. Combines the validation of PositiveInt with the flexibility of nullable values.

from pyvalueobjects import NullablePositiveInt

# Creation
my_integer = NullablePositiveInt(9)

# Creating from None
my_nullable_integer = NullablePositiveInt(None)

# Getting raw value
my_integer.value() # returns -> 9
my_nullable_integer.value() # returns -> None

Positive Or Zero Int

An integer value object that ensures the value is greater than or equal to zero. Useful for representing non-negative quantities or counts.

from pyvalueobjects import PositiveOrZeroInt

# Creation
my_integer = PositiveOrZeroInt(9)

# Getting raw value
my_integer.value() # returns -> 9

Nullable Positive Or Zero Int

A non-negative integer value object that can also be None. Combines the validation of PositiveOrZeroInt with the flexibility of nullable values.

from pyvalueobjects import NullablePositiveOrZeroInt

# Creation
my_integer = NullablePositiveOrZeroInt(9)

# Creating from None
my_nullable_integer = NullablePositiveOrZeroInt(None)

# Getting raw value
my_integer.value() # returns -> 9
my_nullable_integer.value() # returns -> None

Negative Int

An integer value object that ensures the value is strictly less than zero. Useful for representing negative quantities or values.

from pyvalueobjects import NegativeInt

# Creation
my_integer = NegativeInt(-9)

# Getting raw value
my_integer.value() # returns -> -9

Nullable Negative Int

A negative integer value object that can also be None. Combines the validation of NegativeInt with the flexibility of nullable values.

from pyvalueobjects import NullableNegativeInt

# Creation
my_integer = NullableNegativeInt(-9)

# Creating from None
my_nullable_integer = NullableNegativeInt(None)

# Getting raw value
my_integer.value() # returns -> -9
my_nullable_integer.value() # returns -> None

Negative Or Zero Int

An integer value object that ensures the value is less than or equal to zero. Useful for representing non-positive quantities or values.

from pyvalueobjects import NegativeOrZeroInt

# Creation
my_integer = NegativeOrZeroInt(-9)

# Getting raw value
my_integer.value() # returns -> -9

Nullable Negative Or Zero Int

A non-positive integer value object that can also be None. Combines the validation of NegativeOrZeroInt with the flexibility of nullable values.

from pyvalueobjects import NullableNegativeOrZeroInt

# Creation
my_integer = NullableNegativeOrZeroInt(-9)

# Creating from None
my_nullable_integer = NullableNegativeOrZeroInt(None)

# Getting raw value
my_integer.value() # returns -> -9
my_nullable_integer.value() # returns -> None

String value-objects

String

A basic string value object that ensures the value is a valid string. Provides type safety and validation for string values.

from pyvalueobjects import String

# Creation
my_str = String('potato')

# Getting raw value
my_str.value() # returns -> 'potato'

Nullable String

A string value object that can also be None. Useful for optional string fields.

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

A string value object that ensures the value is not an empty string. Useful for required string fields that must contain content.

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

A non-empty string value object that can also be None. Combines the validation of NonEmptyString with the flexibility of nullable values.

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

A string value object that ensures the value is a valid UUID v4 format. Useful for representing unique identifiers.

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

A UUID v4 value object that can also be None. Combines the validation of Uuid4 with the flexibility of nullable values.

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

A string value object that ensures the value is a valid ISO 8601 date format. Useful for representing dates and timestamps in a standardized format.

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'

Data structures value-objects

ArrayList

A value object that ensures all elements in a list are of a specific type. Provides type safety and validation for list contents.

from pyvalueobjects import ArrayList
from pyvalueobjects import Int

# Creation
my_int_array = ArrayList(Int)([39])

# Getting raw value
my_int_array.value()  # returns -> [39]

Nullable ArrayList

A list value object that can also be None, with type validation for its elements. Combines the validation of ArrayList with the flexibility of nullable values.

from pyvalueobjects import ArrayList
from pyvalueobjects import Int

# Creation
my_int_array = ArrayList(Int)([39])
my_null_array = ArrayList(Int)(None)

# Getting raw value
my_int_array.value()  # returns -> [39]
my_null_array.value()  # returns -> None

Security value-objects

CVE

A string value object that ensures the value is a valid Common Vulnerabilities and Exposures (CVE) identifier format. Useful for representing security vulnerability identifiers.

from pyvalueobjects import Cve

# Creation
my_cve = Cve('CVE-2014-9418')

# Getting raw value
my_cve.value()  # returns -> 'CVE-2014-9418'

Nullable CVE

A CVE value object that can also be None. Combines the validation of CVE with the flexibility of nullable values.

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

A string value object that ensures the value is a valid Common Platform Enumeration (CPE) format. Useful for representing platform and software identifiers.

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

A CPE value object that can also be None. Combines the validation of CPE with the flexibility of nullable values.

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

Contributing

Contributions are welcome! Feel free to submit a Pull Request. But Make sure you are not contributing to a mirror repository. Check the following Repository Status section to identify the primary repository.

πŸ”„ Repository Status

This project may be a mirror of another primary repository. Below is a list of all related repositories, indicating whether they are mirrors and their approximate sync frequency:

Service Repository URL Type Sync Frequency
Codeberg https://codeberg.org/n1nj4t4nuk1/python-value-objects Primary N/A
Github https://github.com/n1nj4t4nuk1/python-value-objects Mirror Every commit

⚠️ Note: If you are viewing this repository on a platform like GitHub, GitLab, Gitea, Forgejo, etc., be aware that it might not be the main repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸ’Š A collection of Value Objects to save time by generalizing types and format validations.

Topics

Resources

License

Stars

Watchers

Forks