Code Monkey home page Code Monkey logo

autoyaml's Introduction

autoyaml because config should be easy

Autoconfig is a config generator that takes a dictionary, writes it to a file and loads it back as a dictionary.

The aim of this project is to standardise the way python projects create and feed parameters into python applications without having to rewrite the same IO functions every time.

Installation

pip install autoyaml

Usage

Write your config either from an interactive terminal or from a script

from autoyaml import write_config

conf = {
   'parameter1': 1,
   'parameter2': 'something'
}

application_name = 'app_name'

write_config(conf,application_name)

Load your config from another python application

from autoyaml import load_config

class My_Class(object):
   def __init__(self, **kwargs):
      self.parameter1 = kwargs['parameter1']
      self.parameter2 = kwargs['parameter2']
      self.show_parameters()

   def show_parameters(self):
      print('parameter1 : {}'.format(self.parameter1))
      print('parameter2 : {}'.format(self.parameter2))


if __name__ == "__main__":
   my_class = My_Class(**load_config('app_name'))

Password Protected Encryption

from autoyaml import write_config
from getpass import getpass

conf = {
   'secret_key': getpass('Secret Key? ')
}

application_name = 'app_name1'

write_config(conf, application_name, encrypted=True)

Loads the same but requires password input by default

from autoyaml import load_config

class My_Class(object):
   def __init__(self, **kwargs):
      self.secret_key = kwargs['secret_key']
      self.show_parameters()

   def show_parameters(self):
      print('the last character of your secret it {}'.format(self.secret_key[-1]))


if __name__ == "__main__":
   my_class = My_Class(**load_config('app_name1'))

Create a custom password function

from autoyaml import load_config, write_config
def BAD_PASSWORD_FUNCTION():
   return 'password123'

write_config({'foo':'bar'},'app_name2', encrypted=True, password_function=BAD_PASSWORD_FUNCTION)

print(load_config('app_name3', password_function=BAD_PASSWORD_FUNCTION)

autoyaml's People

Contributors

dependabot[bot] avatar martyni 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.