Git Product home page Git Product logo

simplesettings's Introduction

simplesettings-py

Python settings files done simple. PyPI Page here

Installation

Simply run python -m pip install simplesettings-py in your terminal.

Simple docs

simplesettings.clear() Clears the settings file


simplesettings.save() Saves a variable to the settings file, example:

import simplesettings_py as settings

settings.save("Data", 123)
settings.save("MoreData", "real")
settings.save("MoreMoreData", {"You can save": "a dictionary!"}, table="dictionaries")
settings.save("EvenMoreMoreData", ("A", "B", "C"), table="tuples")

Outputted settings file (by default .settings):

(main)
Data = 123
MoreData = real

(dictionaries)
MoreMoreData = {'You can save': 'a dictionary!'}

(tuples)
EvenMoreMoreData = ('A', 'B', 'C')

simplesettings.save_dict() Saves an entire dictionary to the settings file in simplesettings format, example:

import simplesettings_py as settings

a_dictionary = {
	"Data": 123,
	"MoreData": "One Two Three",
	"MoreMoreData": {"You can save": "a dictionary!"},
	"EvenMoreMoreData": ("A", "B", "C")
}

settings.save_dict(a_dictionary, table="saved_dict")

Outputted settings file:

(saved_dict)
Data = 123
MoreData = One Two Three
MoreMoreData = {'You can save': 'a dictionary!'}
EvenMoreMoreData = ('A', 'B', 'C')

simplesettings.load() Loads the settings file into a dictionary; example:

import simplesettings_py as settings

print(settings.load())

Output: {'saved_dict': {'Data': 123, 'MoreData': 'One Two Three', 'MoreMoreData': {'You can save': 'a dictionary!'}, 'EvenMoreMoreData': ('A', 'B', 'C')}}

You can use this to get certain values, example:

import simplesettings_py as settings

settings = settings.load()
print(settings["saved_dict"]["Data"])

Output: 123


simplesettings.loads() The same as simplesettings.load() but takes a simplesettings string as an argument, example:

import simplesettings_py as settings

print(settings.loads(
"""
(main)
Data = 123
MoreData = real
  
(dictionaries)
MoreMoreData = {'You can save': 'a dictionary!'}
  
(tuples)
EvenMoreMoreData = ('A', 'B', 'C')
"""
))

Output: {'main': {'Data': 123, 'MoreData': 'real'}, 'dictionaries': {'MoreMoreData': {'You can save': 'a dictionary!'}}, 'tuples': {'EvenMoreMoreData': ('A', 'B', 'C')}}

Note that the load() and loads() functions will automatically convert strings of integers, floats, booleans, tuples, lists and dictionaries to the right type, don't forget to convert them back to the type you want (which you should be doing anyway x))


Please feel free to create a pull request if you encounter any issues or something that could be improved

simplesettings's People

Contributors

stuntlover-tm avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.