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.3.tar.gz (10.3 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.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toomanyconfigs-0.2.3.tar.gz
  • Upload date:
  • Size: 10.3 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.3.tar.gz
Algorithm Hash digest
SHA256 21537b4acd72b29689ca31f4403c6bc9051ea046724ca4cb7243a99ababb7f4a
MD5 130fc56cccfa9376c82da9f254858c58
BLAKE2b-256 f55baee9335305f59930ada4aeb832ffef777f640afcadea243f19476d0c29fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toomanyconfigs-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 009db2424856ce3a93cfec238fcd6e51bf1469a117b90e5053ee7fb37e9dea1a
MD5 816359ccfb5ae2d48946734e2a517b51
BLAKE2b-256 adde007f9903dd937629f20e04d9189fe338920b4ab3b229020498b33f82e7e8

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