Coder Social home page Coder Social logo

jade_config's Introduction

Jade Config

A Python package to quickly and easily make configs, or other things that your program needs to remember.

We've all written data to a text file for later. Sometimes It's fine. Sometimes we read from each line trying to put more than one value in one file, then it gets confusing. This package is a quick and easy way to save data using the shelve module from the Python Standard Library.

This module uses no third-party libraries. It only uses the Standard Library so it downloads really quick.

On Windows, Jade Config, creates three files.

file.bak
file.dat
file.dir

On Mac, Jade Config creates only one.

file.db

Usage


Jade Config is very simple to use.

Download it with:

pip install jade-config

Import it using:

>>> from jade_config import config

Create a file with:

>>> file = config.Config("fileName", True)

Replace 'fileName' with the name of the file. You do not need to include any file extensions. The last parameter is an optional logging feature. Set it to 'True' to enable logging, or to 'False' to disable it. It is False by default, so you can just omit the parameter if you don't need logging. The log file is located at (name of file).log.txt. Each file gets a seperate log file. Enabling logging could be a security vulnerabilty depending on what data you're storing.

From there you can set values

>>> file.setValue("username", "nfoert")
True

The first parameter is the key. The second parameter is the value. This returns True if the value was written, otherwise it throws a UnableToSetValue exception. You can set more than one value per file. Just use different keys, or you'll overwrite the last entry.

After you set a value, you can get it.

>>> get = file.getValue("username")
>>> print(get)
"nfoert"

You can use .getValue for any key in your file.

You can also remove a key from the file.

>>> file.removeKey("username")
[fileName] Removed key 'username'

The full example

from jade_config import config

file = config.Config("test", True)
file.setValue("username", "nfoert")
get = file.getValue("username")
print(get)

file.removeKey("username")

Future updates


  • CLI Support
  • The ability to choose the file location (may need to use a different library than shelve.)

Warning: The files created by this library can still be read by others, eg. hackers, by using Jade Config, shelve or others. Don't store sensitive data like passwords or API Keys! It's certainly more secure than text files, but be careful!

Changelog


  • [1.1.2] [5/24/23] Fixed a bug where if you tried to getValue() a key that couldn't be found, It would throw an UnboundLocalError.
  • [1.1.1] [5/23/23] Made errors more descriptive, added removeKey(), and made the database correctly close after it's done being used.
  • [1.0.1] Patch fixing a small logging confusion
  • [1.0.0] Initial release

jade_config's People

Contributors

nfoert avatar

Watchers

 avatar  avatar

jade_config's Issues

Quiet mode

All functions should get an optional parameter quiet that prevents it logging anything.

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.