Rickled

Starting

Rickle is a lightweight tool for loading and writing very small Python objects to YAML or JSON representations. This is especially useful for creating YAML config files and serialising them as Python objects. Works great in interactive Python environments like notebooks.

To install:

pip install rickled

Create a YAML file, call it “config.yaml”:

BASIC:
 text: test
 dictionary:
   one: 1
   two: 2
 number: 2
 list:
   - one
   - two
   - four
   - name: John
     age: 20
 USERNAME:
   type: env
   load: USERNAME
 callable_lambda:
   type: lambda
   load: "lambda: print('hell world!')"
 datenow:
   type: lambda
   import:
     - "from datetime import datetime as dd"
   load: "lambda: print(dd.utcnow().strftime('%Y-%m-%d'))"
 test_function:
   type: function
   name: test_function
   args:
     x: 7
     y: null
     s: hello world
     any:
       - 1
       - hello
   import:
     - "math"
   load: >
     def test(x, y, s, any):
       print(math.e)
       iii = 111
       print(iii)
       print(x,s)
       if y:
         print(type(y))
       else:
         print(y)
       for i in any:
         print(i)

Then import the tools:

>> from rickled import Rickle

>> config = Rickle('./config.yaml', deep=True, load_lambda=True)

>> config.BASIC.dictionary
{'one' : 1, 'two' : 2}

>> config.BASIC.callable_lambda()
hell world!

About

Rickle is quick to use tool mainly meant to easily encapsulate config YAML files in other Zipfian Science tools.

Changes and history

See Changelog for version history.

Version 0.2.4 (2022-09-02):

  • Added ability to get nodes by using Unix style paths to get to nodes.

  • Added a safe load environment variable “RICKLE_SAFE_LOAD” to override all lambda loads (as a safety measure).

  • Added search_path to search for a key in the Rickle.

  • Removed includes_self_reference due to confusion.

  • Added a third way to load CSV files, see example documentation.

  • Added load_as_rick to add_api_json_call.

Contributors

  • Fabian Sperrle