Skip to main content

TangledHub Config reader/writter

Project description

Build Status Stable Version Coverage Python License

thconfig

Overview

TangledHub library for config with a focus on asynchronous functions

Licensing

thconfig is licensed under the BSD license. Check the LICENSE for details

Installation

pip install thconfig

Testing

docker-compose build thconfig-test ; docker-compose run --rm thconfig-test

Building

docker-compose build thconfig-build ; docker-compose run --rm thconfig-build

Publish

docker-compose build thconfig-publish ; docker-compose run --rm -e PYPI_USERNAME=__token__ -e PYPI_PASSWORD=__SECRET__ thconfig-publish

THCONFIG supported in this library

...

Testing

docker-compose build thconfig-test ; docker-compose run --rm thconfig-test

Usage

File

Configuration from file

setup

'''
A class to handle reading and writing configuration data from file
'''

# you need to provide file with data { configuration }
config_path = 'example_1.json'

# create instance of FileConfig
config = FileConfig(config_path)

fetch

'''
Reads config data from file
'''

# you need to provide file with data { configuration }
config_path = 'example_1.json'

# create instance of FileConfig
config = FileConfig(config_path)

# load data from configuration file if success
res: bool = (await config.fetch()).unwrap()

commit

'''
Write config data to file
'''

# you need to provide file with data { configuration }
config_path = 'example_1.json'

# create instance of FileConfig
config = FileConfig(config_path)

# set title
config['title'] = 'Config Example'

config.title2 = 'Config Example'

# this function change title in file
(await config.commit()).unwrap()

CouchConfig

Configuration from couchdb

setup

'''
A class to handle reading and writing configuration data from couchdb

instantiate CouchConfig:
        parameters:
            uri: str
'''

# this is url for couchdb where are configuration data 
URI = 'http://tangledhub:tangledhub@couchdb-test:5984/thconfig-test/test_couch_config'

# create intance CouchConfig and set URI property
config = CouchConfig(URI)

fetch

Fetching configuration document from couchdb

'''
Fetching document and store data in self._state
Sync couchdb -> self._state
https://docs.couchdb.org/en/stable/api/document/common.html#get--db-docid

Fetch:
    parameters:
        self: CouchConfig
'''

# this is url for couchdb where are configuration data 
URI = 'http://tangledhub:tangledhub@couchdb-test:5984/thconfig-test/test_couch_config'

# create intance CouchConfig and set URI property
config = CouchConfig(URI)

# fetching data from database
fetched_data = (await config.fetch()).unwrap()

commit

Commit changes in configuration data in documment in couchdb

'''
Commit document, save data from self._state to couchdb
Sync self._state -> couchdb
https://docs.couchdb.org/en/stable/api/document/common.html#put--db-docid

Commit:
    parameters:
        self: CouchConfig
'''

# this is url for couchdb where are configuration data 
URI = 'http://tangledhub:tangledhub@couchdb-test:5984/thconfig-test/test_couch_config_commit_changes'

# create intance CouchConfig and set URI property
config = CouchConfig(URI)

title = 'Couch Config Example'
database = {'server': '192.168.1.1'}

# set title and database
config['title'] = title
config['database'] = database

# commit
commit_0 = (await config.commit()).unwrap()

EtcdConfig

Configuration from EtcdConfig

setup

'''
A class to handle reading and writing configuration data from etcd
instantiate EtcdConfig:
    parameters:
        HOST: str
        PORT: int
'''

# you need to provide host and port
HOST = 'etcd-test'
PORT = 2379

# create instance of EtcdConfig
config = EtcdConfig(host = HOST, port = PORT)

fetch

Fetching configuration document from etcd

'''
Fetching document and store data in self._state
Sync etcd -> self._state
https://aetcd3.readthedocs.io/en/latest/reference/client.html#aetcd3.client.Etcd3Client.get_all

Fetch:
    parameters:
        self: EtcdConfig
'''

# you need to provide host and port
HOST = 'etcd-test'
PORT = 2379

# create instance of EtcdConfig
config = EtcdConfig(host = HOST, port = PORT)

# fetching data from etcd
fetched_data = (await config.fetch()).unwrap()

commit

Commit changes in configuration data to etcd

'''
Commit document, save data from self._state to etcd
Sync self._state -> etcd
https://aetcd3.readthedocs.io/en/latest/reference/client.html#aetcd3.client.Etcd3Client.put

commit changes:
    parameters:
        self: EtcdConfig
'''

# you need to provide host and port
HOST = 'etcd-test'
PORT = 2379

# create instance of EtcdConfig
config = EtcdConfig(host = HOST, port = PORT)

title = 'Couch Config Example'
database = {'server': '192.168.1.1'}

# set title and database
config['title'] = title
config['database'] = database

# commit
commit_0 = (await config.commit()).unwrap()

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

thconfig-0.9.8.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

thconfig-0.9.8-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file thconfig-0.9.8.tar.gz.

File metadata

  • Download URL: thconfig-0.9.8.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/5.4.109+

File hashes

Hashes for thconfig-0.9.8.tar.gz
Algorithm Hash digest
SHA256 ab4316808c065dfd6b11d778b936c6b866b86add9aa60bcbb4da7af1fac51653
MD5 ff60d5fd890e435d35e5a49605129953
BLAKE2b-256 3088beef467d1aa72d8c14cf7c2275e0d44c847b3e4e5577156a6210a0286dfd

See more details on using hashes here.

File details

Details for the file thconfig-0.9.8-py3-none-any.whl.

File metadata

  • Download URL: thconfig-0.9.8-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/5.4.109+

File hashes

Hashes for thconfig-0.9.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5494b156a88f692a44e844b85c12e841f55610bd5067e0078fffe29bc7d0a49b
MD5 a29396038cdcbd61494abd39722ac19e
BLAKE2b-256 ba66b4eba5ea984b4d93d39f9955e46d3c4281f73d3a7738c6fa110174f0398f

See more details on using hashes here.

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