Skip to main content

No project description provided

Project description

TooManyConfigs

A simple Python library for TOML-based configuration with interactive setup and clipboard integration.

Installation

pip install toomanyconfigs

Basic Usage

from toomanyconfigs import TOMLConfig

class Test(TOMLConfig):
    foo: str = None  # Each field that should prompt user input should be 'None'

if __name__ == "__main__":
    Test.create()  # Without specifying a path, TOMLConfig will automatically make a .toml in your cwd with the name of your inheriting class.

Output:

WARNING  | toomanyconfigs.core:create:164 - [TooManyConfigs]: Config file not found, creating new one
INFO     | toomanyconfigs.core:create:182 - [Test]: Missing fields detected: ['foo']
[Test]: Enter value for 'foo' (or press Enter to paste from clipboard): bar
SUCCESS  | toomanyconfigs.core:_prompt_field:226 - [Test]: Set foo

Advanced Usage

from toomanyconfigs import TOMLConfig
from loguru import logger as log

class Test2(TOMLConfig):
    foo: str = None
    bar: int = 33  # We'll set bar at 33 to demonstrate the translation ease between dynamic python objects and .toml

if __name__ == "__main__":
    t = Test2.create()  # initialize a dataclass from a .toml
    log.debug(t.bar)  # view t.bar
    t.bar = 34  # override python memory
    log.debug(t.bar)  # view updated t.bar
    t.write()  # write to the specified .toml file
    data = t.read()  # ensure overwriting
    log.debug(data)

Output:

WARNING  | toomanyconfigs.core:create:164 - [TooManyConfigs]: Config file not found, creating new one
INFO     | toomanyconfigs.core:create:182 - [Test2]: Missing fields detected: ['foo']
[Test2]: Enter value for 'foo' (or press Enter to paste from clipboard): bar
SUCCESS  | toomanyconfigs.core:_prompt_field:226 - [Test2]: Set foo
DEBUG    | __main__:<module>:35 - 33
DEBUG    | __main__:<module>:37 - 34
DEBUG    | toomanyconfigs.core:write:241 - [TooManyConfigs]: Writing config to test2.toml
DEBUG    | __main__:<module>:40 - {'foo': 'bar', 'bar': 34}

Subconfigs

from toomanyconfigs import TOMLConfig, TOMLSubConfig
from loguru import logger as log

class Test4(TOMLSubConfig):
    foo: str = None

class Test3(TOMLConfig):
    key: str = "val"
    sub_config: Test4

if __name__ == "__main__":
    t = Test3.create()
    log.debug(t.__dict__)

Output:

WARNING  | toomanyconfigs.core:create:164 - [TooManyConfigs]: Config file not found, creating new one
INFO     | toomanyconfigs.core:create:182 - [Test3]: Missing fields detected: ['sub_config']
DEBUG    | toomanyconfigs.core:create:39 - [TooManyConfigs]: Building subconfig named 'test4'
INFO     | toomanyconfigs.core:create:57 - [Test4]: Missing fields detected: ['foo']
[Test4]: Enter value for 'foo' (or press Enter to paste from clipboard): bar
SUCCESS  | toomanyconfigs.core:_prompt_field:73 - [Test4]: Set foo
SUCCESS  | toomanyconfigs.core:create:190 - [Test3]: Created Test4 for sub_config

API Configurations

Basic API Usage

import asyncio
from toomanyconfigs import API
from loguru import logger as log

if __name__ == "__main__":
    obj = API()
    response = asyncio.run(obj.api_request("get"))
    log.debug(response)

Output:

WARNING  | toomanyconfigs.core:create:179 - [TooManyConfigs]: Config file not found, creating new one
INFO     | toomanyconfigs.core:create:197 - APIConfig: Missing fields detected: ['headers', 'routes', 'vars']
DEBUG    | toomanyconfigs.core:create:41 - [TooManyConfigs]: Building subconfig named 'headersconfig'
SUCCESS  | toomanyconfigs.core:create:205 - APIConfig: Created HeadersConfig for headers
INFO     | toomanyconfigs.core:create:59 - RoutesConfig: Missing fields detected: ['base', 'shortcuts']
[RoutesConfig]: Enter value for 'base' (or press Enter to paste from clipboard): http://example.com
SUCCESS  | toomanyconfigs.core:_prompt_field:84 - [RoutesConfig]: Set base
SUCCESS  | toomanyconfigs.core:create:68 - RoutesConfig: Created Shortcuts for shortcuts
DEBUG    | toomanyconfigs.api:api_request:146 - Attempting request to API: method=get, path=http://example.com

Generated TOML:

[headers]
authorization = "Bearer ${API_KEY}"
accept = "application/json"

[routes]
base = "http://example.com"

[vars]

[routes.shortcuts]

Advanced API Usage

import asyncio
from dataclasses import field
from pathlib import Path
from toomanyconfigs import API, APIConfig, HeadersConfig, RoutesConfig, VarsConfig, Shortcuts
from loguru import logger as log

if __name__ == "__main__":
    src = (Path.cwd() / "json_api.toml")
    src.touch(exist_ok=True)

    base_url = 'https://jsonplaceholder.typicode.com/'
    quick_routes = {
        "c": "/comments?postId=1"
    }
    routes = RoutesConfig(
        base=base_url,
        shortcuts=Shortcuts.create(_source=src, **quick_routes)
    )


    class JSONVars(VarsConfig):
        api_key: str = None


    json_vars = JSONVars.create(
        source=src,
        name="vars"
    )

    cfg = APIConfig.create(_source=src, routes=routes, vars=json_vars)
    json_placeholder = API(cfg)
    log.debug(json_placeholder.config.__dict__)
    response = asyncio.run(json_placeholder.api_get("c"))
    log.debug(response)

Output:

DEBUG    | toomanyconfigs.core:create:41 - [TooManyConfigs]: Building subconfig named 'shortcuts'
DEBUG    | toomanyconfigs.core:create:41 - [TooManyConfigs]: Building subconfig named 'vars'
INFO     | toomanyconfigs.core:create:59 - JSONVars: Missing fields detected: ['api_key']
[JSONVars]: Enter value for 'api_key' (or press Enter to paste from clipboard): ****
SUCCESS  | toomanyconfigs.core:_prompt_field:84 - [JSONVars]: Set api_key
DEBUG    | toomanyconfigs.core:create:153 - [TooManyConfigs]: Building config from json_api.toml
INFO     | toomanyconfigs.core:create:197 - APIConfig: Missing fields detected: ['headers']
SUCCESS  | toomanyconfigs.core:create:205 - APIConfig: Created HeadersConfig for headers
DEBUG    | toomanyconfigs.api:api_request:146 - Attempting request to API: method=get, path=https://jsonplaceholder.typicode.com//comments?postId=1
DEBUG    | __main__:<module>:151 - Response(status=200, method='get', body=[...])

Generated TOML:

[routes]
base = "https://jsonplaceholder.typicode.com/"

[vars]
api_key = "****"

[headers]
authorization = "Bearer ${API_KEY}"
accept = "application/json"

[routes.shortcuts]
c = "/comments?postId=1"

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

toomanyconfigs-0.2.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toomanyconfigs-0.2.5-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file toomanyconfigs-0.2.5.tar.gz.

File metadata

  • Download URL: toomanyconfigs-0.2.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11

File hashes

Hashes for toomanyconfigs-0.2.5.tar.gz
Algorithm Hash digest
SHA256 b2d65b5c1e4256d762dc7fe51db6f69857d6c2e7a0feea5a8b63acb9008d1752
MD5 8f44fb3d6cf5e934022cae241ae6729c
BLAKE2b-256 ae75b3084e52d9799766057370c789ef5ba16886fd6506c6d46244ec25d9b355

See more details on using hashes here.

File details

Details for the file toomanyconfigs-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: toomanyconfigs-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11

File hashes

Hashes for toomanyconfigs-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6880237979f19a6e192b28f25e4266127f8742e898bc9d05550d9e6d28738438
MD5 8df7f8550101d42c127affc1ddaad806
BLAKE2b-256 5622dfe83db029eeb0c6c26464daca6e93dfd281f55f86e79f7cb70ef78f92e1

See more details on using hashes here.

Supported by

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