| Python | |
| Package | |
| Meta |
pycsi
pycsi is a simple python library to validate data and/or build a validation schema.
Installation
pip install pycsi
Usage
We might begin by creating validation callables such:
def is_divisible_by_three(x: float):
return x % 3 == 0
def is_all_positive(numbers: list[float]):
return all(number > 0 for number in numbers)
def is_quotient_positive(x: float, y: float):
return x / y > 0
Then we can instantiate a Subvalidator instance and the validation callables to it:
from pycsi import Subvalidator
first_subvalidator = Subvalidator(
"First condition",
"Number is not divisible by 3",
is_divisible_by_three,
x=3
)
second_subvalidator = Subvalidator(
"Second condition",
"Not every number is positive",
is_all_positive,
numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, -10],
)
third_subvalidator = Subvalidator(
"Third condition",
"Quotient is not positive",
is_quotient_positive,
x=10,
y=2,
)
Finally we can create a validator object and add the subvalidators to it.
from pycsi import Validator
validator = Validator()
validator.add(first_subvalidator)
validator.add(second_subvalidator)
validator.add(third_subvalidator)
validator.run()
The validator will run all the subvalidators and the unvalidated_set property will return a set of the failed subvalidators.
print(validator.unvalidated_set)
{ValidatorError(condition='Second condition', error_message='Not every number is positive')}
Asynchronous Usage
This library also supports async validation. We can create asyncronous validation callables such:
import asyncio
async def async_is_divisible_by_three(x: float) -> bool:
await asyncio.sleep(0.1)
return is_divisible_by_three(x)
async def async_is_all_positive(numbers: list[float]) -> bool:
await asyncio.sleep(0.1)
return is_all_positive(numbers)
Instead of using the Subvalidator API, we are going to use the AsyncSubvalidator in the next step:
from pycsi import AsyncSubvalidator
first_subvalidator = AsyncSubvalidator(
"First condition",
"Number is not divisible by 3",
async_is_divisible_by_three,
x=10,
)
second_subvalidator = AsyncSubvalidator(
"Second condition",
"Not every number is positive",
async_is_all_positive,
numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
)
Same for the Validator API, we will switch the the AsyncValidator.
from pycsi import AsyncValidator
validator = AsyncValidator()
validator.add(first_subvalidator)
validator.add(second_subvalidator)
validator.run()
print(validator.unvalidated_set)
{ValidatorError(condition='First condition', error_message='Number is not divisible by 3')}
Metadata
Release files for pycsi 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycsi-0.1.0.tar.gz | 5.1 kB | Without provenance | Details for pycsi-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycsi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pycsi-0.1.0-py3-none-any.whl |
Total release size: 12.1 kB
Release files / pycsi-0.1.0.tar.gz
| Download URL | pycsi-0.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b7e2d7e0bc2c2f12240a28a5d72fc41c2f26ccedadf321a4b0f71f820808857
|
|
BLAKE2b-256 checksum How to use checksums |
593da142c8dd3e95af07e4675b47ed75e3900a6d4d2229a5bebf1035d656d3b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / pycsi-0.1.0-py3-none-any.whl
| Download URL | pycsi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77538b9ec88d2d12f0373695d9ad588d621e46e30662d14d77ecb7390cc023d2
|
|
BLAKE2b-256 checksum How to use checksums |
8fa21e18d3ff770f3aa8f39a4da608fe6aa1feb4d2333ba264f96ed1b3f398d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for pycsi 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.