Core Concepts
params-proto provides three main decorators for different use cases. This guide introduces each one.
The Three Decorators
1. @proto.cli - Create a CLI Entry Point
Wraps a function to automatically parse command-line arguments:
Usage:
When to use: Script entry points, CLI tools, one-off functions.
2. @proto - Define Reusable Configurations
Creates a configuration class that can be instantiated multiple times:
When to use: Libraries, reusable components, multiple instances needed.
3. @proto.prefix - Global Singleton Configurations
Creates singleton configuration groups with automatic CLI prefixes:
CLI usage:
When to use: Global configuration namespaces, multiple configuration groups.
Quick Comparison
| Feature | @proto.cli | @proto | @proto.prefix |
|---|---|---|---|
| Purpose | CLI entry point | Reusable config | Global singleton |
| Scope | Function wrapper | Class definition | Singleton namespace |
| Instances | One per call | Multiple allowed | One global |
| CLI | Automatic | Manual (wrap in @proto.cli) | Automatic (with prefix) |
| Access | Function params | Instance attributes | Class attributes |
| Example | train() | Config() | Model.name |
Common Patterns
Pattern 1: Simple CLI Function
Best for: Simple scripts, one-off utilities.
Pattern 2: Reusable Configuration Class
Best for: Libraries, components used in multiple places.
Pattern 3: Namespaced Global Configs
Best for: Large projects with multiple config namespaces.
Pattern 4: Union Types (Subcommands)
CLI usage:
Best for: Choosing between different configurations.
Type Annotations
params-proto uses Python's type hints to:
- Generate help text with type information
- Automatically convert CLI string arguments to proper types
- Validate parameter types
Supported types:
- Basic:
int,float,str,bool - Collections:
List[T],Dict[K, V] - Optional:
Optional[T](seeUnion Typesfor workaround) - Dataclasses and custom classes
- Enums:
Enumsubclasses
Next Steps
- For scripts: Read Configuration Patterns
- For advanced use: Read
Advanced Patterns - For CLI details: Read CLI Fundamentals
- For type details: Read Type System
Related
- Welcome - Introduction and quick start
- CLI Fundamentals - Basic CLI features
- CLI Patterns - Advanced CLI patterns
- Configuration Patterns - Functions vs classes in depth
Union Types- Subcommands and optional parametersAdvanced Patterns- Prefixes and composition