argclass

PyPI Version Python Versions Coverage Tests License

Declarative CLI parser with type hints, config files, and environment variables.

Build type-safe command-line interfaces using Python classes. Get IDE autocompletion, automatic --help generation, and seamless integration with config files and environment variables - all with zero dependencies.

import argclass

class Server(argclass.Parser):
    host: str = "127.0.0.1"
    port: int = 8080
    debug: bool = False

server = Server()
server.parse_args()
print(f"Starting server on {server.host}:{server.port}")
$ python server.py --host 0.0.0.0 --port 9000 --debug
Starting server on 0.0.0.0:9000

Why argclass?

Type-Safe

Define arguments with Python type hints. Get automatic validation and conversion.

Zero Dependencies

Built on stdlib argparse. No external dependencies required.

IDE Support

Full autocompletion and type checking in your editor.

Feature

argclass

argparse

click/typer

Type hints → arguments

Yes

No

Yes

IDE autocompletion

Yes

No

Yes

Config file support

Built-in

No

No

Environment variables

Built-in

No

Plugin

Secret masking

Built-in

No

No

Argument groups

Reusable

Limited

No

Dependencies

stdlib

stdlib

Many

Installation

pip install argclass

Tip

Download PDF Documentation for offline reading.

Quick Examples

Groups

Organize related arguments:

import argclass

class DatabaseGroup(argclass.Group):
    host: str = "localhost"
    port: int = 5432

class Parser(argclass.Parser):
    debug: bool = False
    db = DatabaseGroup()

parser = Parser()
parser.parse_args(["--db-host", "prod.db", "--db-port", "5432"])
# parser.db.host == "prod.db"

Config Files

Load defaults from INI, JSON, or TOML:

import argclass

class Parser(argclass.Parser):
    host: str = "localhost"
    port: int = 8080

parser = Parser(config_files=[
    "/etc/myapp.ini",
    "~/.config/myapp.ini",
])

Environment Variables

Read from environment with a prefix:

import argclass

class Parser(argclass.Parser):
    host: str = "localhost"
    port: int = 8080

parser = Parser(auto_env_var_prefix="MYAPP_")
# Reads from MYAPP_HOST, MYAPP_PORT

Get Started

Quick Start

5 minute introduction

Learn the basics: arguments, types, flags, and environment variables.

Quick Start
Tutorial

Complete walkthrough

Build a real CLI application step by step.

Tutorial

Documentation

Indices and tables