easyclasses-1.0.1
توضیحات
Lightweight dataclass library.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | easyclasses-1.0.1 |
| نام | easyclasses |
| نسخه کتابخانه | 1.0.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | ZeroIntensity |
| ایمیل نویسنده | <zintensitydev@gmail.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/easyclasses/ |
| مجوز | MIT |
# Easyclasses
## Lightweight alternative to dataclasses
### Quick Example
```py
from easyclasses import EasyClass
class MyClass(EasyClass):
a: str
b: str
c: str = "test"
print(MyClass("a", "b", c="hi")) # MyClass(a='a', b='b', c='hi')
```
### Installation
#### Linux/Mac
```
python3 -m pip install -U easyclasses
```
#### Windows
```
py -3 -m pip install -U easyclasses
```
### Performance
Based on `benchmarks.py`, easyclasses is over 6x faster than the built-in dataclasses module.
On top of that, it's also outperforms `NamedTuple`.
### Usage
#### Basics
Easyclasses API is pretty similar to dataclasses.
The main difference between dataclasses is that easyclasses uses a subclass instead of a decorator, like so:
```py
from easyclasses import EasyClass
class MyEasyClass(EasyClass):
a: str
```
You can also provide default arguments the same way:
```py
from easyclasses import EasyClass
class MyEasyClass(EasyClass):
a: str
b: str = "h"
```
You can pass subclass arguments to enable or disable certain features:
```py
from easyclasses import EasyClass
class MyEasyClass(EasyClass, eq=False, immutable=True):
a: str
MyEasyClass("a") == MyEasyClass("a") # False
MyEasyClass("a").a = "test" # TypeError
```
If you aren't planning on using features like `__eq__`, then you can use `LightEasyClass`, which has features like that removed, allowing it to be faster than the normal `EasyClass`:
```py
from easyclasses import LightEasyClass
class MyEasyClass(LightEasyClass): # works the same
a: str
```
#### Factories
If you need a default argument for a mutable object (such as `list` or `dict`), you can use the `factory` function:
```py
from easyclasses import EasyClass, factory
class MyEasyClass(EasyClass):
a: list = factory(list)
```
#### Validators
You can set a validator using the `validator` function:
```py
from easyclasses import EasyClass, validator
class MyEasyClass(EasyClass):
a: str = validator(str, lambda v: v == "hi")
MyEasyClass("hi") # OK
MyEasyClass("a") # AssertionError
```
You can even use it with `factory`:
```py
from easyclasses import EasyClass, validator, factory
class MyEasyClass(EasyClass):
a: list = validator(factory(list), lambda v: v == [1])
MyEasyClass([1, 2]) # AssertionError
```
نحوه نصب
نصب پکیج whl easyclasses-1.0.1:
pip install easyclasses-1.0.1.whl
نصب پکیج tar.gz easyclasses-1.0.1:
pip install easyclasses-1.0.1.tar.gz