Skip to main content

InPlat config adapters

Project description

tests codecov pypi versions

Config adapters with pydantic behavior

  • json
  • yaml
  • toml
  • hcl2
  • environ
  • .env
  • TODO: multiline PEM keys load with cryptography

Examples

.env

APP_VERSION=v0.0.1a1
APP_HTTP_HOST=myname.lan
HTTP_2=true
APP_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8M4vd2AmKTW0/nqc
YQBi/bRZjkVezdGHi+zH5kYvm/2hRANCAATxEs1e8hqwpYCTk3amfq/UnGyvViPZ
Midz4nFzQvcq7A9Ju/wvEfLDjA131kh2Sk+x3dgLxhTf7yKJXZC0jg3d
-----END PRIVATE KEY-----"

config.yaml

http:
  port: 10001
  transport:
    timeout: 60.0
    buffer_size: 65535
  interfaces:
    - 127.0.0.1
    - 192.168.0.1
version: 1

yaml with env, dotenv and args overrides

from datetime import datetime
from ipaddress import IPv4Address
from os import environ
from pathlib import Path
from typing import Dict, Union

from pydantic import BaseModel, Field

from ipl_config import BaseSettings


class TcpTransport(BaseModel):
    timeout: float  # from config file
    buffer_size: int = Field(0.01, env='BUFF_SIZE')  # from env


class Http(BaseModel):
    host: str  # from dotenv
    bind: str  # from env
    port: int  # from config file
    interfaces: list[IPv4Address]  # from config file
    transport: TcpTransport
    http2: bool = Field(env='HTTP_2')  # from dotenv


class IplConfig(BaseSettings):
    version: str  # from kwargs
    created: datetime  # from env
    http: Http  # env also works for complex objects
    private_key: str  # from dotenv
    group_by_id: Union[Dict[int, str], None]


if __name__ == "__main__":
    environ['app_http_bind'] = '1.1.1.1'
    environ['buff_size'] = '-1'
    environ['app_created'] = '2000-01-01T00:00:00Z'
    environ['app_group_by_id_0'] = 'root'


    root = Path('.')

    cfg = IplConfig(
        version='v0.0.1a1',
        env_file=root / '.env',
        config_file=root / 'config.yaml',
    )
    cfg.write_json(indent=4)
    print()

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

ipl-config-0.1.10.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

ipl_config-0.1.10-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file ipl-config-0.1.10.tar.gz.

File metadata

  • Download URL: ipl-config-0.1.10.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for ipl-config-0.1.10.tar.gz
Algorithm Hash digest
SHA256 127a309c164f3756fdb2eec77b6518ed81c835c30d1ae8fd0d9d4dc1655035aa
MD5 3b83084833ff331a1ab333b91ce1d7b5
BLAKE2b-256 18a2db759c127a102cae6d72b7c0da90dcfaec5051444a01f7d07f1b0070fc09

See more details on using hashes here.

File details

Details for the file ipl_config-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: ipl_config-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for ipl_config-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 274da32eca30ce0e3a6d3147dc985821ed4d7626229d0c3437f4c857fdb253d4
MD5 12002b54cb2776db99ea748a8d14f5bf
BLAKE2b-256 cd1b02403d82e1d197869988a856767914ec93732fd844545a631f4b39d440cc

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