pydantic-spark-1.0.1
توضیحات
Converting pydantic classes to spark schemas
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | pydantic-spark-1.0.1 |
| نام | pydantic-spark |
| نسخه کتابخانه | 1.0.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Peter van 't Hof' |
| ایمیل نویسنده | peter.vanthof@godatadriven.com |
| آدرس صفحه اصلی | https://github.com/godatadriven/pydantic-spark |
| آدرس اینترنتی | https://pypi.org/project/pydantic-spark/ |
| مجوز | MIT |
[](https://github.com/godatadriven/pydantic-spark/actions/workflows/python-package.yml)
[](https://codecov.io/gh/godatadriven/pydantic-spark)
[](https://badge.fury.io/py/pydantic-spark)
[](https://github.com/godatadriven/pydantic-spark/actions/workflows/codeql-analysis.yml)
# pydantic-spark
This library can convert a pydantic class to a spark schema or generate python code from a spark schema.
### Install
```bash
pip install pydantic-spark
```
### Pydantic class to spark schema
```python
import json
from typing import Optional
from pydantic_spark.base import SparkBase
class TestModel(SparkBase):
key1: str
key2: int
key2: Optional[str]
schema_dict: dict = TestModel.spark_schema()
print(json.dumps(schema_dict))
```
#### Coerce type
Pydantic-spark provides a `coerce_type` option that allows type coercion.
When applied to a field, pydantic-spark converts the column's data type to the specified coercion type.
```python
import json
from pydantic import Field
from pydantic_spark.base import SparkBase, CoerceType
class TestModel(SparkBase):
key1: str = Field(extra_json_schema={"coerce_type": CoerceType.integer})
schema_dict: dict = TestModel.spark_schema()
print(json.dumps(schema_dict))
```
### Install for developers
###### Install package
- Requirement: Poetry 1.*
```shell
poetry install
```
###### Run unit tests
```shell
pytest
coverage run -m pytest # with coverage
# or (depends on your local env)
poetry run pytest
poetry run coverage run -m pytest # with coverage
```
##### Run linting
The linting is checked in the github workflow. To fix and review issues run this:
```shell
black . # Auto fix all issues
isort . # Auto fix all issues
pflake . # Only display issues, fixing is manual
```
نیازمندی
| مقدار | نام |
|---|---|
| >=2.5.2,<3.0.0 | pydantic |
| >=3.1.2,<3.3.0 | pyspark |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8,<4.0 | Python |
نحوه نصب
نصب پکیج whl pydantic-spark-1.0.1:
pip install pydantic-spark-1.0.1.whl
نصب پکیج tar.gz pydantic-spark-1.0.1:
pip install pydantic-spark-1.0.1.tar.gz