*Zenif takes a quantum leap forward with a suite of enhancements designed to supercharge your development experience. This update introduces smart memory management, more informative deprecation warnings, streamlined CLI interactions, and โ drum roll, please โ a powerful new Schema module for bulletproof data validation. While we've made some breaking changes to keep Zenif sleek and intuitive, the payoff in improved functionality and clarity is well worth it.*
๐ Introducing Schema Module: Data Validation, Zenif Style
Introducing our brand new Schema module, your new best friend for data integrity:
- Define data structures with a fluent, method-chaining approach that prioritizes readability and expressiveness.
- Validate input with pinpoint precision using a rich set of built-in validators.
- Seamlessly integrate with the CLI module for robust, schema-driven command-line interfaces.
- Create custom validators to fit your unique data validation needs.
- Complex form flows? Use conditionals and transform functions to handle your user's data.
python
def to_lowercase(s: str) -> str:
return s.lower()
def remove_whitespace(s: str) -> str:
return ''.join(s.split())
Schema(
username=StringF()
.name("username")
.has(Length(min=3, max=50, err="Your username must be between 3 and 50 characters."))
.has(Regex(r"^[a-zA-Z0-9_]+$")),
age=IntegerF()
.name("age")
.has(Value(max=120))
.optional(),
driver_license=StringF().name("driver_license").when(
lambda data: data.get('age', 0) >= 16,
"Driver's license is required for ages 16 and above"
),
email=StringF()
.name("email")
.pre(to_lowercase)
.post(remove_whitespace)
.has(EmailValidator()),
profile=DictF()
.name("profile")
.key_type(StringF())
.value_type(StringF())
.optional(),
)
Dive deeper into the world of schemas with our [shiny new documentation](/docs/modules/schema.md). It's a page-turner, we promise!
๐ Decorators Module: Smarter and More Informative
- `cache` now features a `max_size` argument, allowing you to cap the cache size and keep memory usage in check.
- `deprecated` gets an upgrade with the new `expected_removal` argument, providing clearer timelines for deprecation.
- We've bid farewell to `retry_exponential_backoff` in favor of the more concise `retry_expo`.
- Under the hood, `deprecated` now leverages Zenif's own logger for deprecation messages.
- Our test suite has been expanded to cover these new features comprehensively.
๐ป CLI Module: Cleaner, More Powerful, and Schema-Aware
- We've renamed `argument` to `arg` and `option` to `kwarg` for more intuitive use.
- Introducing the `install_setup_command()` method: now you can easily generate a shell script to install your CLI app as a Zsh command alias.
- We've squashed a pesky type hint error in `NumberPrompt`.
- All prompt types now support schema validation, opening the floodgates for a whole new world of prompt types! Bring robust data integrity to your interactive CLIs with ease. And pro-tip by the way, to define a schema, give your prompts IDs that you can use in your your schema. It's like a spell that turns your prompts into schema-ready powerhouses!
- `ChoicePrompt` now comes with built-in type checking, ensuring it plays nice with String schema fields only.
- `CheckboxPrompt` gets a visual upgrade: it now sports a snazzy underline beneath the 'X' if the current position overlaps with a selected item.
- `TextPrompt` and `PasswordPrompt` have learned to ignore arrow keys, because sometimes less is more.
- `TextPrompt`, `NumberPrompt`, and `PasswordPrompt` now come with a magical screen-overflow handling: they'll gracefully truncate the start of long responses, ensuring your CLI stays sleek without losing a single character of input.
๐ Log Module: More Flexibility, Less Clutter
- For those who prefer simplicity, we've added new `"simple"` and `"short"` premade formats.
- We've removed the warning log on `Logger` initialization when Stacking > Enabled is set to True, reducing unnecessary output.
- We've added a `StructuredLogger` class that takes in the same arguments as `Logger`, but also includes "kwargs" in a dictionary. We plan to add JSON mode for file streams.
โจ Polishing Touches
- Our GitHub project link now sports the more fitting label "GitHub" instead of "Homepage".
- The `README` now includes a pronunciation guide for "Zenif" (it's "Zenith", by the way).
- We've given this very changelog a makeover, infusing it with personality and clearer explanations to better showcase Zenif's evolution.
- New documentation for the Schema module has been added, complete with examples and integration guides.
*While these changes bring exciting new capabilities, please note that some are breaking changes. Be sure to review your use of exponential retry decorators and CLI argument decorators when upgrading to this version.*