Skip to content

Conversation

@vilsonrodrigues
Copy link
Contributor

Summary

Adds 8 powerful advanced validators to msgspec-ext:

Network & Hardware

  • IPv4Address, IPv6Address, IPvAnyAddress - IP address validation using Python's ipaddress module
  • MacAddress - MAC address validation with multiple format support (colon, dash, dot notation)

String Constraints

  • ConStr - Constrained strings with min_length, max_length, and regex pattern support

Storage & Dates

  • ByteSize - Parse storage sizes with units (B, KB, MB, GB, TB, KiB, MiB, GiB, TiB)
  • PastDate, FutureDate - Date validation for past/future dates using date.today()

Bonus Features

  • Re-exported msgspec.Raw and msgspec.UNSET for convenience

Test Coverage

  • 121 unit tests - Comprehensive validation tests for all types
  • 18 integration tests - End-to-end tests with BaseSettings
  • 220 total tests passing in 0.31s

Examples

New example file examples/08_advanced_validators.py demonstrates:

  1. IP address validation (IPv4, IPv6, any)
  2. MAC address validation
  3. Constrained string validation
  4. Byte size parsing with units
  5. Past/Future date validation
  6. Real-world combined usage

Implementation Details

  • All validators integrate seamlessly with BaseSettings via _dec_hook
  • ClassVar annotations for mutable class attributes
  • Optimized with caching for better performance
  • No JSON validator (removed as unnecessary - use plain str)

Breaking Changes

None - all new features, fully backward compatible.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

vilsonrodrigues and others added 15 commits November 27, 2025 02:18
- Complete project structure overview
- Common commands and workflows
- Release process (always use ./scripts/release.sh)
- Architecture details and optimizations
- Linting, testing, and CI/CD guides
- Troubleshooting tips

This file provides context for Claude Code to work more effectively
with the project without repeating instructions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements 9 new powerful validators:

**Network & Data Types:**
- IPv4Address, IPv6Address, IPvAnyAddress - IP address validation
- Json - JSON string validation
- MacAddress - MAC address with multiple format support

**String Constraints:**
- ConStr - Constrained strings with min/max length and regex patterns

**Storage & Dates:**
- ByteSize - Parse byte sizes with units (KB, MB, GB, KiB, MiB, etc)
- PastDate, FutureDate - Date validation for past/future dates

**Bonus Exports:**
- Added msgspec.Raw and msgspec.UNSET re-exports for convenience

**Test Coverage:**
- Added 67 comprehensive tests (all passing)
- Total: 127 type validator tests

All validators integrate seamlessly with BaseSettings via dec_hook.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Removed Json validator type as it adds unnecessary complexity:
- JSON strings are better validated when used, not when loaded
- Using plain `str` type is clearer and more flexible
- Simplifies _preprocess_env_value logic
- Reduces dec_hook complexity

Updated:
- Removed _Json class from types.py
- Removed Json from all imports and exports
- Removed Json tests (121 tests passing)
- Updated example to remove JSON validation section
- Renamed example to 08_advanced_validators.py

All 121 type tests passing ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Created test_integration.py with 18 integration tests ensuring all
validators work correctly with BaseSettings:

**Test Coverage:**
- Numeric types: PositiveInt, NegativeInt, PositiveFloat
- String validators: EmailStr, HttpUrl, SecretStr
- Database DSNs: PostgresDsn, RedisDsn
- Path validators: FilePath, DirectoryPath
- Network validators: IPv4Address, IPv6Address, IPvAnyAddress, MacAddress
- Storage & Dates: ByteSize, PastDate, FutureDate
- Complete integration: All validators working together

**Test Results:**
- 18 integration tests: ✓ ALL PASSING
- 121 unit tests: ✓ ALL PASSING
- Total: 220 tests passing in 0.31s

Integration tests verify environment variable parsing, type conversion,
and validation work correctly end-to-end with BaseSettings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…port

Major improvements to README.md:

**New Description:**
- Updated from "settings management" to "settings management and validation library"
- Better reflects the dual nature of the project

**Enhanced Type Support Section:**
- **All msgspec native types** - Emphasized full compatibility with msgspec's rich type system
- Added link to msgspec supported types: https://jcristharif.com/msgspec/supported-types.html
- Listed key native types: datetime, UUID, Decimal, collections, etc.
- Highlighted msgspec.Raw and msgspec.UNSET re-exports

**26 Custom Validators - Organized by Category:**
- 🔢 Numeric Constraints (8 types)
- 🌐 Network & Hardware (4 types) - NEW: IP addresses, MAC addresses
- ✉️ String Validators (4 types)
- 🗄️ Database & Connections (3 types)
- 📁 Path Validators (2 types)
- 💾 Storage & Dates (3 types) - NEW: ByteSize, PastDate, FutureDate
- 🎯 Constrained Strings (2 types) - NEW: ConStr

**New Advanced Usage Examples:**
- Storage size parsing with ByteSize
- Date validation (past/future)
- Complete examples for all new validators

**Updated Comparison Table:**
- Added "Validators" row: msgspec-ext (26) vs pydantic-settings (~15)
- Emphasized validator advantage

**Better Structure:**
- Quick Start shows validators immediately
- Type Support section right after installation
- Clear categorization with emojis for easy scanning
- Complete validator table with all 26 types

Result: README now clearly communicates that msgspec-ext is both a
settings management tool AND a comprehensive validation library with
26 specialized validators + all msgspec native types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Enhanced project metadata to reflect evolution:

**Updated Description:**
- Old: "Fast settings management using msgspec"
- New: "High-performance settings management and validation library extending msgspec"
- Cleaner, emphasizes extension of msgspec

**Added Keywords (11 total):**
- msgspec, settings, configuration
- validation, validators
- pydantic (for discoverability)
- environment-variables, dotenv
- type-validation
- fast, performance

**Enhanced Classifiers:**
- Added "Intended Audience :: System Administrators"
- Added "Topic :: System :: Systems Administration"
- Added "Typing :: Typed" (for type-safe libraries)

These changes improve:
- 🔍 PyPI search discoverability
- 📊 Better project categorization
- 🎯 Clear communication of dual purpose (settings + validation)
- 🏷️ Relevant keywords for users searching for pydantic alternatives

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vilsonrodrigues vilsonrodrigues force-pushed the feat/add-validators-phase2 branch from 2ec729e to 62627cd Compare December 3, 2025 15:43
- Renamed examples/08_advanced_validators.py to 07_advanced_validators.py
- Updated README references to use correct example number
- Fixed integration test structure and removed redundant tests
- All 220 tests passing
- Export dec_hook and enc_hook for use with msgspec structs
- Add 'With msgspec Structs' section to Quick Start
- Add msgspec struct examples to validator sections (Network, Storage)
- Add 'Use Cases' section with real-world examples:
  - API Request/Response validation
  - Configuration files with validation
  - Message queue data validation (MessagePack)
- Add enc_hook for serializing custom types to JSON/MessagePack
- Update pyproject.toml to ignore UP038 lint rule
- All validators now work seamlessly with both BaseSettings and msgspec.Struct
- Add practical output examples in Quick Start section
- Show model_dump() and model_dump_json() outputs for BaseSettings
- Add print outputs in API Request/Response example
- Add outputs in Configuration Files example
- Enhance Nested Configuration with full dump example
- Add Secret Masking serialization examples
- Add ByteSize serialization output
- Helps users understand what to expect when serializing settings
Fix CI formatting check failure
@vilsonrodrigues
Copy link
Contributor Author

/merge

@github-actions github-actions bot merged commit afe72e3 into msgflux:main Dec 3, 2025
10 checks passed
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

✅ PR merged successfully by @vilsonrodrigues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant