dc-input simplifies the process of populating dataclass instances through an interactive command line interface. With features like nested schemas, undo support, and custom parsers, it streamlines data entry and enhances scripting efficiency. Ideal for rapid prototyping and structured configuration.
dc-input is a powerful library designed to facilitate the interactive filling of dataclass instances directly through the command line interface. It streamlines the process of data entry, making it particularly useful for quick prototyping or structured configuration tasks. Key features include:
The library addresses the common challenges faced when writing scripts for user input, validation, and parsing. dc-input simplifies this process with a single function call, reducing boilerplate code and minimizing potential errors.
To illustrate its functionality, here’s a brief example:
from dataclasses import dataclass
from dc_input import get_input
test class User:
name: str
age: int | None
user = get_input(User)
print(user) # Outputs collected user data
A more complex illustration demonstrates how to use dc-input in real projects—such as collecting data for a music student:
from dataclasses import dataclass, field, asdict
import json
from dc_input import get_input
@dataclass
class MusicStudent:
id: int
name: Name
date_of_birth: Any
... # Additional fields as per the schema
# Collect input interactively
student_data = get_input(MusicStudent)
For a complete executable script and detailed interactions, refer to the full example in the README.
Future development will focus on extensive testing, support for attrs, and potential integrations with libraries like pydantic and sqlalchemy.
Engagement from the community is encouraged. Users are invited to test the library's limits with unique schemas and to contribute feedback for improvements. Check out discussions and share suggestions on the GitHub repository.
No comments yet.
Sign in to be the first to comment.