Library for validating and parsing HTTP response objects with decorators
Project description
Request Rule Decorators
Библиотека для валидации и парсинга HTTP-ответов с использованием декораторов.
Установка
pip install -e .
Для разработки с тестами:
pip install -e ".[dev]"
Быстрый старт
from request_rule_decorators import ResponseHandler, Validator, Parser
@ResponseHandler.handlers(
Validator.STATUS_CODE().whitelist([200, 201]),
Validator.CONTENT_TYPE().equals("application/json"),
Validator.JSON("$.username").whitelist().values(["john_doe"]),
Validator.JSON("$.age").range(18, 100),
Parser.JSON("$.age").save_to("parsed_age"),
)
async def my_function():
# Ваша функция, возвращающая response объект
return response
result = await my_function()
# result.response - оригинальный response
# result.valid.ERRORS - список ошибок валидации
# result.valid.PARSED - распарсенные данные
# result.is_valid() - проверка валидации
Документация
Подробная документация доступна в файле DOCS.md
Запуск тестов
pytest tests/
Запуск демонстрационного примера
python demo.py
Структура проекта
request_rule_decorators/- основной пакет библиотекиdto.py- DTO классы (ValidationError, ValidationData, WithValid)decorator.py- декоратор ResponseHandlerrules.py- фабрика правил (Validator, Parser)exceptions.py- кастомные исключенияvalidators/- валидаторы (JSON, Headers, StatusCode, ContentType, HTML)parsers/- парсеры (JSON, HTML)
tests/- тестыdemo.py- демонстрационный файлDOCS.md- подробная документация
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file request_rule_decorators-0.1.0.tar.gz.
File metadata
- Download URL: request_rule_decorators-0.1.0.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41bee03e9277984efba4ad00954547ef10a863ca7607a82ef92c6bbe9270f917
|
|
| MD5 |
d275ea589afa5555b756d49ee622dc01
|
|
| BLAKE2b-256 |
c7c71c2ee0c2f8fcfe18d9b5f403b3c584ff58e448bd9db3a6539e5d62c24806
|
File details
Details for the file request_rule_decorators-0.1.0-py3-none-any.whl.
File metadata
- Download URL: request_rule_decorators-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be3218c528eff3dc799d627a449a13079798d32ea33a7903b0f8743aede0bdc
|
|
| MD5 |
ab0c7d66deb039010c6c46f07aeb333f
|
|
| BLAKE2b-256 |
2a49f365e0f314e8cb486b6d6eab78ccfbb06041f82c4e392c2341f8b6b39aad
|