Skip to main content

Coma

Configurable command management for humans.

PyPI version fury.io PyPI license PyPI pyversions PyPI status

Code style Documentation Status

Introduction

coma provides a modular and declarative interface for defining commands, associated configuration files, and initialization routines. Configs and initializations can be command-specific or injected as reusable components in multiple commands.

from coma import command, wake
from dataclasses import dataclass


# Step 1: Declare one or more configurations.
@dataclass
class RemoteCfg:
    server: str = "localhost"
    port: int = 9001


# Step 2: Declare one or more commands.
@command
def push(remote: RemoteCfg, **data):
    # Code for pushing data to remote. Mocked here as print statements.
    print(f"Pushing data: {data}")
    print(f"To url: {remote.server}:{remote.port}")


# Step 3: Launch!
if __name__ == "__main__":
    wake()

Key Features

The declarations in the above example provide a rich command line interface for invoking your program. Assuming this code is in a file called main.py, you get:

Direct command parameter access

A command (push) that is invoked by name and command parameters (remote and data) that are directly available as command line arguments (also by name):

$ python main.py push \
    remote::server=127.0.0.1 remote::port=8000 \
    data::header=foo data::content=bar
Pushing data: {'header': 'foo', 'content': 'bar'}
To url: 127.0.0.1:8000

Config serialization

Configs that are automatically serialized to file based on their name (config remote is saved to remote.yaml in this case), enabling long-term persistence:

$ ls
main.py
remote.yaml
$ cat remote.yaml
server: localhost
port: 9001

Both YAML and JSON are supported!

And lots more!

Including:

  • Removing the boilerplate of argparse while retaining full argparse interoperability and customizability for complex use cases.
  • Providing a comprehensive set of hooks to easily tweak, replace, or extend coma's template-based default behavior.
  • Integrating with omegaconf's extremely rich and powerful configuration management features.

Installation

pip install coma

Getting Started

Excited? Jump straight into the extensive tutorials and examples of the official documentation.

Changelog

From version 2.1.0:

  • Significant design changes that break backwards compatibility:
    • Removed coma.register(). Everything happens via the @command decorator.
    • Folded all coma.initiate() functionality into coma.wake().
    • Simplified all hook protocols and added new utilities for user-defined hooks.
  • Greatly improved command signature inspection:
    • More robust parsing and invocation of command parameters.
    • New inline config parameters!

From version 2.0.1:

  • Changed coma.wake() from warnings-based to Exception-based error handling.

From version 1.0.1:

  • Add @command decorator
  • Changed default prefix separator from : to :: to avoid conflict with dictionary notation
  • Minor improvements and bug fixes

Metadata

Release files for coma 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coma 3.0.1
File Size Uploaded
coma-3.0.1.tar.gz 46.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coma 3.0.1
File Interpreter ABI Platform
coma-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 90.7 kB

Release files / coma-3.0.1.tar.gz

Download URL coma-3.0.1.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d380fd166b8f2833cb97b1c805702192f3e71fc39bf70e6efd17cf8f67b18a35
BLAKE2b-256 checksum
How to use checksums
544d00a73ac578e588a4205a74713807fa0bef19aa61b35c38fcad82475e0955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / coma-3.0.1-py3-none-any.whl

Download URL coma-3.0.1-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f8dfcbb494926d0dbb46d0c9f03caa98599cfe8be5a4bccb9c50bfcce1210d1
BLAKE2b-256 checksum
How to use checksums
952b026fc2f6abf0a8569e3adf472c8a7f1475f56e1633cf6633c76d858b127a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.1

1 release file

2.0.0

1 release file

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page