semvec/pypi-packages huggingface dataset:
validpeas 0.2
Tools for structured validations
Keywords: validation

# validpeas
Small library to create structured validations


## Example

```python
# Elemental validators


@processor_from_validator
@make_validator()
def is_string(data: Any) -> bool:
    return isinstance(data, str)


@processor_from_validator
@make_validator()
def is_valid_json(json_string: str) -> bool:
    try:
        loads(json_string)
        return True
    except ValueError:
        return False


@processor_from_validator
@make_validator()
def has_numbers_field(data: dict) -> bool:
    return "numbers" in data


@processor_from_validator
@make_validator()
def is_list(data: Any) -> bool:
    return isinstance(data, list)


@processor_from_validator
@make_validator()
def is_integer(data: Any) -> bool:
    return isinstance(data, int)


@processor_from_validator
@make_validator()
def length_is_greater_than_5(data: list) -> bool:
    return len(data) > 5


@processor_from_validator
@make_validator()
def ascending_pair(numbers: tuple[int, int]) -> bool:
    return numbers[0] < numbers[1]


# Composite validators


@make_composite_processor()
def all_list_items_are_integers(numbers: list[Any]) -> list[ValidationResult]:
    return list(map(is_integer, numbers))


@make_composite_processor()
def is_in_ascending_order(numbers: list[int]) -> list[ValidationResult]:
    return list(map(ascending_pair, pairwise(numbers)))


@make_composite_processor()
def main_validator(data: Any) -> list[ValidationResult]:
    is_string_result = is_string(data)

    is_valid_json_result = is_valid_json(data, dependencies=[is_string_result])

    json_data = loads(data) if is_valid_json_result.passed else None

    has_numbers_field_result = has_numbers_field(
        json_data, dependencies=[is_valid_json_result]
    )

    numbers = json_data["numbers"] if has_numbers_field_result.passed else None

    is_list_result = is_list(numbers, dependencies=[has_numbers_field_result])

    length_is_greater_than_5_result = length_is_greater_than_5(
        numbers, dependencies=[is_list_result]
    )
    all_list_items_are_integers_result = all_list_items_are_integers(
        numbers, dependencies=[is_list_result]
    )

    is_in_ascending_order_result = is_in_ascending_order(
        numbers, dependencies=[all_list_items_are_integers_result]
    )

    return [
        is_string_result,
        is_valid_json_result,
        has_numbers_field_result,
        is_list_result,
        length_is_greater_than_5_result,
        all_list_items_are_integers_result,
        is_in_ascending_order_result,
    ]


samples = [
    5,
    "gfdgsgfsggfds",
    '{"asdf": [1, 2, 3, 5, 4]}',
    '{"numbers": [1, 2, 3]}',
    '{"numbers": [1, 2, 3, 4, 5, "a"]}',
    '{"numbers": [1, 2, 3, "b"]}',
    '{"numbers": [1, 2, 3, 4, 6, 5, 7, 8, 9, 10]}',
    '{"numbers": [1, 2, 3, 4, 5, 6]}',
]

for sample in samples:
    result = main_validator(sample)
    print(human_text_result_report(result))
    print()
```
metis-client 0.7.1
Metis infra API client in Python
Requires Python: >=3.8
Keywords: metis,client

# Metis API client

[![DOI](https://zenodo.org/badge/563802198.svg)](https://doi.org/10.5281/zenodo.7693569)
[![PyPI](https://img.shields.io/pypi/v/metis_client.svg?style=flat)](https://pypi.org/project/metis-client)

<p align="center"><img src="https://github.com/metis-science/metis-client/blob/master/metis-client.png" width="300" /></p>

This library allows for programmatic interactions with the [Metis infrastructure](https://github.com/basf/metis-bff).


## Installation

`pip install metis_client`

## Usage

There are two client flavors: **asyncronous** `asyncio` client
and simplified **synchronous** client.

### Asynchronous client

An asynchronous client is `MetisAPIAsync`. Example of usage:

```python
from metis_client import MetisAPIAsync, MetisTokenAuth

async def main():
    async with MetisAPIAsync(API_URL, auth=MetisTokenAuth("VERY_SECRET_TOKEN")) as client:
        print(await client.v0.auth.whoami())
        data = await client.v0.datasources.create(content)
        results = await client.v0.calculations.create_get_results(data["id"])
        print(resuls)
```

See `examples` directory for more examples.

### Synchronous client

A synchronous client is `MetisAPI`. Example of usage:

```python
from metis_client import MetisAPI, MetisTokenAuth

client = MetisAPI(API_URL, auth=MetisTokenAuth("VERY_SECRET_TOKEN"), timeout=5)
data = client.v0.datasources.create(content)
results = client.v0.calculations.create_get_results(data["id"], timeout=False)
print(results)
```

NB in development one can replace a `VERY_SECRET_TOKEN` string with the development user email, e.g.
`admin@test.com` (refer to **users_emails** BFF table).


## Contributing

Please give a minute to the [contribution guide](https://github.com/metis-science/metis-client/blob/master/CONTRIBUTING.md). Note, that our [changelog](https://github.com/metis-science/metis-client/blob/master/CHANGELOG.md) is maintained fully automatically via [GitHub actions](https://github.com/metis-science/metis-client/tree/master/.github/workflows).


## License

Author Sergey Korolev, Tilde Materials Informatics

Copyright 2023 BASF SE

BSD 3-Clause