Name | light-types JSON |
Version |
1.2.2
JSON |
| download |
home_page | None |
Summary | Parse, don't validate |
upload_time | 2024-08-16 20:36:26 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | None |
keywords |
phantom types
value object
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Light Types
[![image](https://img.shields.io/pypi/v/light-types.svg)](https://pypi.python.org/pypi/light-types)
[![codecov](https://codecov.io/gh/likeinlife/light-types/graph/badge.svg?token=7QUSPNC4CQ)](https://codecov.io/gh/likeinlife/light-types)
[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://rye.astral.sh)
[![image](https://img.shields.io/pypi/l/light-types.svg)](https://github.com/likeinlife/light-types/blob/main/LICENSE)
<a href="http://mypy-lang.org/" target="_blank"><img src="https://img.shields.io/badge/mypy-checked-1F5082.svg" alt="Mypy checked"></a>
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://img.shields.io/pypi/pyversions/light-types.svg)](https://pypi.python.org/pypi/light-types)
"Parse, don't validate"
Compatible with PydanticV2
Inspired by [Phantom types](https://github.com/antonagestam/phantom-types/)
# Examples
## Sample
```python
from light_types import LightType
class StartsWithString(str, LightType):
@classmethod
def validate(cls, value: str) -> bool:
return value.startswith("String")
```
## With Pydantic
```python
from light_types import LightType
class StartsWithString(str, LightType):
@classmethod
def validate(cls, value: str) -> bool:
return value.startswith("String")
class MyModel(BaseModel):
value: StartsWithString
assert TypeAdapter(MyModel).validate_python({"value": "StringOk"})
```
## QLightType
```python
from light_types import QLightType, NumericQ
class NumericBetween5And10(int, QLightType):
validator = (NumericQ() > 5).custom(lambda n: n < 10)
```
```python
from light_types import QLightType, StringQ
class StartsWithString(str, QLightType):
validator = StringQ().startswith("String")
```
```python
from light_types import QLightType, StringQ
class StringWith2O(str, QLightType):
validator = StringQ().startswith("String") & StringQ().custom(lambda s: s.count("o") >= 2)
```
```python
from light_types import QLightType, StringQ
class StringWith2O(str, QLightType):
validator = StringQ().startswith("String") | ~StringQ().custom(lambda s: s.count("o") >= 2)
```
```python
from light_types import QLightType, StringQ, LengthQ
class StringWith2O(str, QLightType):
validator = StringQ().startswith("foo") & (LengthQ[str]() > 5)
```
# Tests, linting, formatting
- `rye test | lint | fmt`
Raw data
{
"_id": null,
"home_page": null,
"name": "light-types",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "phantom types, value object",
"author": null,
"author_email": "likeinlife <likeinlife@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/60/fe/27a4a4fc9fdcffe67897a7d6abb56f6344cc74ffdc85c1829c90dc02ad9b/light_types-1.2.2.tar.gz",
"platform": null,
"description": "# Light Types\n\n[![image](https://img.shields.io/pypi/v/light-types.svg)](https://pypi.python.org/pypi/light-types)\n[![codecov](https://codecov.io/gh/likeinlife/light-types/graph/badge.svg?token=7QUSPNC4CQ)](https://codecov.io/gh/likeinlife/light-types)\n[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://rye.astral.sh)\n[![image](https://img.shields.io/pypi/l/light-types.svg)](https://github.com/likeinlife/light-types/blob/main/LICENSE)\n<a href=\"http://mypy-lang.org/\" target=\"_blank\"><img src=\"https://img.shields.io/badge/mypy-checked-1F5082.svg\" alt=\"Mypy checked\"></a>\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![image](https://img.shields.io/pypi/pyversions/light-types.svg)](https://pypi.python.org/pypi/light-types)\n\n\"Parse, don't validate\"\n\nCompatible with PydanticV2\n\nInspired by [Phantom types](https://github.com/antonagestam/phantom-types/)\n\n# Examples\n\n## Sample\n\n```python\nfrom light_types import LightType\n\n\nclass StartsWithString(str, LightType):\n @classmethod\n def validate(cls, value: str) -> bool:\n return value.startswith(\"String\")\n```\n\n## With Pydantic\n\n```python\nfrom light_types import LightType\n\n\nclass StartsWithString(str, LightType):\n @classmethod\n def validate(cls, value: str) -> bool:\n return value.startswith(\"String\")\n\nclass MyModel(BaseModel):\n value: StartsWithString\n\nassert TypeAdapter(MyModel).validate_python({\"value\": \"StringOk\"})\n```\n\n## QLightType\n\n```python\nfrom light_types import QLightType, NumericQ\n\nclass NumericBetween5And10(int, QLightType):\n validator = (NumericQ() > 5).custom(lambda n: n < 10)\n```\n\n```python\nfrom light_types import QLightType, StringQ\n\nclass StartsWithString(str, QLightType):\n validator = StringQ().startswith(\"String\")\n```\n\n```python\nfrom light_types import QLightType, StringQ\n\nclass StringWith2O(str, QLightType):\n validator = StringQ().startswith(\"String\") & StringQ().custom(lambda s: s.count(\"o\") >= 2)\n```\n\n```python\nfrom light_types import QLightType, StringQ\n\nclass StringWith2O(str, QLightType):\n validator = StringQ().startswith(\"String\") | ~StringQ().custom(lambda s: s.count(\"o\") >= 2)\n```\n\n```python\nfrom light_types import QLightType, StringQ, LengthQ\n\nclass StringWith2O(str, QLightType):\n validator = StringQ().startswith(\"foo\") & (LengthQ[str]() > 5)\n```\n\n# Tests, linting, formatting\n\n- `rye test | lint | fmt`",
"bugtrack_url": null,
"license": null,
"summary": "Parse, don't validate",
"version": "1.2.2",
"project_urls": {
"Homepage": "https://pypi.org/project/light-types/",
"Repository": "https://github.com/likeinlife/light-types/"
},
"split_keywords": [
"phantom types",
" value object"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "659899acdf995697b12350092ab8e3c07e4130e5374db67f8d6dded7474e2a0f",
"md5": "d24f50acdf48a84cb291fd6d34968104",
"sha256": "52b12ccc620a461081303aa3402b8c08f6564a1916a13ad6bcfcd05eb58d82ff"
},
"downloads": -1,
"filename": "light_types-1.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d24f50acdf48a84cb291fd6d34968104",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 9824,
"upload_time": "2024-08-16T20:36:24",
"upload_time_iso_8601": "2024-08-16T20:36:24.873436Z",
"url": "https://files.pythonhosted.org/packages/65/98/99acdf995697b12350092ab8e3c07e4130e5374db67f8d6dded7474e2a0f/light_types-1.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "60fe27a4a4fc9fdcffe67897a7d6abb56f6344cc74ffdc85c1829c90dc02ad9b",
"md5": "2dcb01144b766f087497fd3768ef9f51",
"sha256": "be43aafc11b775331235cf7858959b10438f9ef911870a590b61622f7c9aa08d"
},
"downloads": -1,
"filename": "light_types-1.2.2.tar.gz",
"has_sig": false,
"md5_digest": "2dcb01144b766f087497fd3768ef9f51",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 8839,
"upload_time": "2024-08-16T20:36:26",
"upload_time_iso_8601": "2024-08-16T20:36:26.838159Z",
"url": "https://files.pythonhosted.org/packages/60/fe/27a4a4fc9fdcffe67897a7d6abb56f6344cc74ffdc85c1829c90dc02ad9b/light_types-1.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-16 20:36:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "likeinlife",
"github_project": "light-types",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "light-types"
}