Skip to main content

Library to read and write configs using API and CLI with Typer

Project description

The configuration is a JSON structure. We'll use the following for the coming examples.

{
  "courses": {
    "datintro22": {
      "timesheet": {
        "url": "https://sheets.google..."
      },
      "schedule": {
        "url": "https://timeedit.net/..."
      }
    }
  }
}

The format is actually irrelevant to anyone outside of this library, since it will never be accessed directly anyway. But it will be used to illustrate the examples.

We can access values by dot-separated addresses. For instance, we can use courses.datintro22.schedule.url to access the TimeEdit URL of the datintro22 course.

Let's have a look at some usage examples. Say we have the program nytid that wants to use this config module and subcommand.

import typer
import typerconf as config

cli = typer.Typer()
# add some other subcommands
config.add_config_cmd(cli)

We want the CLI command to have the following form when used with nytid.

  nytid config courses.datintro22.schedule.url --set https://timeedit.net/...

will set the configuration value at the path, whereas

  nytid config courses.datintro22.schedule.url

will return it.

Internally, nytid's different parts can access the config through the following API.

import typerconf as config

url = config.get("courses.datintro22.schedule.url")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typerconf-2.1.tar.gz (13.6 kB view hashes)

Uploaded Source

Built Distribution

typerconf-2.1-py3-none-any.whl (16.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page