Skip to main content
https://img.shields.io/pypi/v/byoc.svg https://img.shields.io/pypi/pyversions/byoc.svg https://img.shields.io/readthedocs/byoc.svg https://img.shields.io/github/workflow/status/kalekundert/byoc/Test%20and%20release/master https://img.shields.io/coveralls/kalekundert/byoc.svg

BYOC is a python library for integrating configuration values from any number/kind of sources, e.g. files, command-line arguments, environment variables, remote JSON APIs, etc. The primary goal of BYOC is to give you complete control over your configuration. This means:

  • Complete control over how files, options, etc. are named and organized.

  • Complete control over how values from different config sources are parsed and merged.

  • Support for any kind of file format, argument parsing library, etc.

  • No opinions about anything enforced by BYOC.

To use BYOC, you would create a class with special attributes (called parameters) that know where to look for configuration values. When these parameters are accessed, the desired values are looked up, possibly merged, possibly cached, and returned. Here’s a brief example:

import byoc
from byoc import Key, DocoptConfig, AppDirsConfig

class Greet(byoc.App):
    """
    Say a greeting.

    Usage:
        greet <name> [-g <greeting>]
    """

    # Define which config sources are available to this class.
    __config__ = [
            DocoptConfig,
            AppDirsConfig.setup(name='conf.yml'),
    ]

    # Define how to search for each config value.
    name = byoc.param(
            Key(DocoptConfig, '<name>'),
    )
    greeting = byoc.param(
            Key(DocoptConfig, '-g'),
            Key(AppDirsConfig, 'greeting'),
            default='Hello',
    )

    def main(self):
        self.load(DocoptConfig)
        print(f"{self.greeting}, {self.name}!")

if __name__ == '__main__':
    Greet.entry_point()

We can configure this script from the command line:

$ ./greet 'Sir Bedevere'
Hello, Sir Bedevere!
$ ./greet 'Sir Lancelot' -g Goodbye
Goodbye, Sir Lancelot!

…or from its config files:

$ mkdir -p ~/.config/greet
$ echo "greeting: Run away" > ~/.config/greet/conf.yml
$ greet 'Sir Robin'
Run away, Sir Robin!

This example only scratches the surface, but hopefully you can already get a sense for how powerful and flexible these parameters are. For more information, refer to the following examples (in lieu of complete documentation).

Examples

For some examples of byoc being used in real scripts, check out the Stepwise — Molecular Biology repository. Almost every script in this repository uses byoc. Below are some particular scripts that might be useful:

Simple scripts:

Long but straight-forward scripts:

Complex scripts:

  • serial_dilution.py

    This script features parameters that depend on other parameters. Specifically, the user must provide values for any three of volume, conc_high, conc_low, and factor. Whichever one isn’t specified is inferred from the ones that are. This is implemented by making the byoc parameters (which in this case read only from the command-line and not from any config files) private, then adding public properties that are calculated from the private ones.

  • digest.py

    This script is actually pretty simple, but it makes used of __bareinit__() to download some data from the internet. As alluded to above, __init__() is not called when App instances are initialized from the command-line, because __init__() might require arbitrary arguments and is therefore considered to be part of the python API. Instead, App instances are initialized by calling __bareinit__() with no arguments.

  • ivtt.py

    This script defines a custom Config class to read from a sequence database. (This example might go out of date, though; I have plans to move that custom Config into a different package.)

Metadata

Release files for byoc 0.32.0

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

Source distribution (sdist)

Source distribution for byoc 0.32.0
File Size Uploaded
byoc-0.32.0.tar.gz 68.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for byoc 0.32.0
File Interpreter ABI Platform
byoc-0.32.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 94.9 kB

Release files / byoc-0.32.0.tar.gz

Download URL byoc-0.32.0.tar.gz
Size 68.3 kB
Tags Source
SHA-256 checksum
How to use checksums
57680a292fa1f2fac2467b8c64779dba5ef19204cead2c30ffd884f0f50388e0
BLAKE2b-256 checksum
How to use checksums
133424f62bfe3b12158d589c960a22fe85049b1102be25d0571e2a7b30139957
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.4 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

Release files / byoc-0.32.0-py2.py3-none-any.whl

Download URL byoc-0.32.0-py2.py3-none-any.whl
Size 26.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
024f11009ec25f3fc98e659d7be636b2240fce2e1900b90c4155b96f2c16f538
BLAKE2b-256 checksum
How to use checksums
860bf8b735fc69ccbf2b232095a2459761f450e2aa43acac2706d2588bb1ff95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.4 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.32.0 This release

2 release files

0.31.0

2 release files

0.30.2

2 release files

0.30.1

2 release files

0.30.0

2 release files

0.29.0

2 release files

0.28.1

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.26.0

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