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:
- Nested Schemas: Efficiently manage complex data structures with ease, handling nested dataclasses seamlessly.
- Repeatable Containers: Allow for dynamic data input, such as lists or collections, that can expand as needed during data entry.
- Undo Support: Mistakes happen; easily revert back to previous inputs during the interactive session.
- Defaults and Optional Fields: Eliminate redundant prompts by utilizing predefined default values and optional fields within your dataclasses.
- Custom Parsers: Implement specific parsing routines for specialized input formats effortlessly.
Why Choose dc-input?
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.
Quick Usage Example
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
In-Depth Example
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.
Additional Features
- Real-time Validation: Automatically validate inputs as they are entered based on the dataclass schema.
- Stackable Input: Gather data across multiple levels and structures with integrated support for nested dataclasses.
Roadmap
Future development will focus on extensive testing, support for attrs, and potential integrations with libraries like pydantic and sqlalchemy.
Community Contributions
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.