Skip to main content

Two way configurations mapping helper for Python.

Project description

Build Status Coverage License PyPI

📄⇄🛠 Two way configurations mapping helper for Python.

Get Started

from biconfigs import Biconfigs
configs = Biconfigs('configs.json')

# Simply change the dict, and it will automatically save the changes to file.
configs['options'] = {'debug': True,
                      'username': 'Anthony',
                      'list': [] }

# Access with simple 'x.y.z' style
configs.options.list.append('example')

Content of file configs.json after execution:

{
  "options": {
    "debug": true,
    "list": [
      "example"
    ],
    "username": "Anthony"
  }
}

Install

pip install git+https://github.com/antfu/biconfigs.git

Dependencies

No dependencies required 🎉 Tested on Python 2.6, 2.7, 3.3, 3.4, 3.5, pypy, pypy3

Documentation

High frequency update

Normally, Biconfigs will write the changes to file immediately. But sometime you may want to update values frequently, which will result in a IO bottleneck. So you can use ``with`` statement to prevent auto saving for a while.

with configs:
  for i in range(1000):
    configs['some_key'] = i
# This statement will execute saving process only one time when exiting "with" scope

When to save

Save when: Item create, item delete, list reorder, value change, get_set, etc. NOT sav ing when: Item access, assignment but not changed, etc.

# All the following single statement will cause saving
configs['item'] = 'value'
configs['options'] = {}
configs.options['list'] = []
configs.options.list.append('example')
configs.options['list'] = []
configs.options.clear()
value2 = configs.get_set('item2', 45)

# All the following single statement will NOT cause saving
value = configs.item
configs['item'] = 'value' # The value of 'item' is not changed
value3 = configs.get('item_not_exists', 'default_value')

Get or set

Biconfigs provides a special function get_set for dict. get_set acts just like dict.get(key, default) but it will save the default value to dict if the key is not exists.

License

MIT

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

biconfigs-0.0.9.zip (6.9 kB view details)

Uploaded Source

Built Distribution

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

biconfigs-0.0.9-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file biconfigs-0.0.9.zip.

File metadata

  • Download URL: biconfigs-0.0.9.zip
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for biconfigs-0.0.9.zip
Algorithm Hash digest
SHA256 ca15fdb2da8cd3104b765cede8778ab59f23d05d2368777be60d0a7ed41cb851
MD5 303601f0bbb2e24bb6df5347e3e901e6
BLAKE2b-256 f7326d0c765c0317d19fbb268617d043a92dd09806811d60f809b4250381a866

See more details on using hashes here.

File details

Details for the file biconfigs-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for biconfigs-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7cf93ccc6a99b086330d74dff52957dd9664fa29956b2f3a634cb6778e339647
MD5 4081faa758b06d40bd848a6dedf7eb34
BLAKE2b-256 c8339298c3d32677e24d0063e31ae4dad76a526d20132ede56d3af046f0079bf

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