Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aleppax/upyftsconf
micropython far too simple config file
https://github.com/aleppax/upyftsconf
configuration-files micropython
Last synced: 3 months ago
JSON representation
micropython far too simple config file
- Host: GitHub
- URL: https://github.com/aleppax/upyftsconf
- Owner: aleppax
- License: mit
- Created: 2023-01-06T17:25:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-23T23:30:36.000Z (8 months ago)
- Last Synced: 2024-06-22T12:41:09.285Z (5 months ago)
- Topics: configuration-files, micropython
- Language: Python
- Homepage:
- Size: 43.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - uPyftsConf - MicroPython Far Too Simple Config File. Single file library that writes configurations to itself. (Libraries / Storage)
README
![micropython Far Too Simple Config File!](/upyftsc.jpg "uPyftsConf")
# uPyftsConf
micropython Far Too Simple Config Filea simplicistic way of storing configuration data for projects written in micropython. (single file, 92 lines of code).
## Disclaimer
don't take this script too seriously: even if it does what it's supposed to, it does it in a way that's not at all ordinary. But isn't it fascinating to think that code can rewrite itself?## How it works
copy the file config.py inside a "libs" folder, import it.If you prefer you can edit the file by adding as many dictionaries as you wish before the lines with code, those are factory settings but can be modified afterwards.
You can also add new dictionaries or settings simply by using the method `set(dictionary_name, key_name, value)`
If the dictionary doesn't exist, it creates it and adds the key:value pair.The function `set` writes the new settings both in memory and to the configuration file (config.py), then reloads the module itself.
```micropython
# example
from libs import config
config.set('upyftsconf','I','exist')
```
the file config.py writes these lines inside itself:```micropython
upyftsconf = {
'I' : 'exist',
}
```Do not nest collection items inside dictionaries.
Do not write below this banner:
(and do not delete it)```micropython
#########################################
### micropython far too simple config ###
### do not write below this header ###
```## Usage
```micropython
from libs import config
config.set('dict_name','key','value')
myvalue = config.dict_name['key']
# or
myvalue = config.dict_name.get('key')
```