Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

data2model

kdpv

Tests PyPI version

Python library and CLI tool for generating different Python data classes from data.

Supported data formats:

  • CSV

Supported data classes:

Requirements

  • Python 3.8+

Installation

pip install data2model

Usage

As library

import asyncio
import pathlib

from data_to_model import ModelGenerator


files = [
    {"input": pathlib.Path("example.csv"), "output": pathlib.Path("example.py")},
]


async def model_generator(input_file: pathlib.Path, output_file: pathlib.Path):
    mg = ModelGenerator(input_file)
    model = await mg.get_model()
    await model.save(output_file)


async def main():
    tasks = [model_generator(i["input"], i["output"]) for i in files]
    await asyncio.gather(*tasks)


if __name__ == "__main__":
    asyncio.run(main())

output

As CLI

from single file

$ cat data.csv
col1,col2
1,2
,2.0

$ data2model file -if data.csv -of data.py
$ cat data.py
# This file was generated by data_to_model.
from dataclasses import dataclass
from typing import Any, Dict, Optional, Union


@dataclass
class Data:
    col1: Optional[int]
    col2: Union[float, int]

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "Data":
        col1 = data["col1"]
        col2 = data["col2"]
        return cls(col1=col1, col2=col2)

    def to_dict(self) -> Dict[str, Any]:
        return {"col1": self.col1, "col2": self.col2}

from directory

$ data2model folder -if data -of models

$ ls data
data1.csv  data2.csv

$ ls models
data1.py  data2.py

Metadata

Release files for data2model 0.2.1b0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for data2model 0.2.1b0
File Size Uploaded Provenance
data2model-0.2.1b0.tar.gz 10.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for data2model 0.2.1b0
File Interpreter ABI Platform
data2model-0.2.1b0-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / data2model-0.2.1b0.tar.gz

Download URL data2model-0.2.1b0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8002cd8706d47767db8c46d4fef4bb0f775d30019047fdac2614a6b1f5e10eb6
BLAKE2b-256 checksum
How to use checksums
f023603ddd4ff7db70f6fbe7675fcc03e37d9a0c4b1f7516f76f79476de59ff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.15.19-1-MANJARO

Release files / data2model-0.2.1b0-py3-none-any.whl

Download URL data2model-0.2.1b0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a27e04547df0b67980173c02bfae81f57f5e599aaa5f7759a5ea41c457b7901
BLAKE2b-256 checksum
How to use checksums
fe7234124bb4dcf3980033f6921233d42ec30f287dcad6a7b51a946787c0963f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.15.19-1-MANJARO

Security for data2model 0.2.1b0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page