Skip to main content

This is a simple environment variable solution for .json file, which is based on 'os' and 'json' lib

Project description

Introduce json_env

  • This pak opened base on MIT Licence
  • This is a simple environment variable solution for .json file
  • It's based on 'os' and 'json' libs
  • Use this lib you don't need to worry type issue of 'os.environ' it's all handled by this pak

Install

pip install json_env

Example

Use case

{
  "str": "Asashishi",
  "bool_str": "true",
  "int_str": "107",
  "float_str": "1.07",
  "none_str": "null",
  "none": null,
  "bool": false,
  "int": 107,
  "float": 1.07,
  "array": [
    "Asashishi",
    "true",
    "107",
    "1.07",
    "null",
    null,
    false,
    107,
    1.07
  ],
  "object": {
    "str": "Asashishi",
    "bool_str": "true",
    "int_str": "107",
    "float_str": "1.07",
    "none_str": "null",
    "none": null,
    "bool": false,
    "int": 107,
    "float": 1.07,
    "array": [
      "Asashishi",
      "true",
      "107",
      "1.07",
      "null",
      null,
      false,
      107,
      1.07
    ]
  }
}

How to use

import os
import time
from json_env import load_env, get_env

start: float = time.time()

# load env from json file
load_env(os.path.join(os.getcwd(),"env.json"))

# log the variables and variable's type
print(get_env("str"), type(get_env("str")))
print(get_env("bool_str"), type(get_env("bool_str")))
print(get_env("int_str"), type(get_env("int_str")))
print(get_env("float_str"), type(get_env("float_str")))
print(get_env("none_str"), type(get_env("none_str")))
print(get_env("none"), type(get_env("none")))
print(get_env("bool"), type(get_env("bool")))
print(get_env("int"), type(get_env("int")))
print(get_env("float"), type(get_env("float")))
print(get_env("array"), type(get_env("array")))
array: list = get_env("array")
for item in array:
    print(type(item))
print(get_env("object"), type(get_env("object")))
json_object: dict = get_env("object")
for key, val in json_object.items():
    print(type(val))
print(f"Test total time cost: {time.time() - start}s")

The results are

Asashishi <class 'str'>
true <class 'str'>
107 <class 'str'>
1.07 <class 'str'>
null <class 'str'>
None <class 'NoneType'>
False <class 'bool'>
107 <class 'int'>
1.07 <class 'float'>
['Asashishi', 'true', '107', '1.07', 'null', None, False, 107, 1.07] <class 'list'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'NoneType'>
<class 'bool'>
<class 'int'>
<class 'float'>
{'str': 'Asashishi', 'bool_str': 'true', 'int_str': '107', 'float_str': '1.07', 'none_str': 'null', 'none': None, 'bool': False, 'int': 107, 'float': 1.07, 'array': ['Asashishi', 'true', '107', '1.07', 'null', None, False, 107, 1.07]} <class 'dict'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'NoneType'>
<class 'bool'>
<class 'int'>
<class 'float'>
<class 'list'>
Test total time cost: 0.001172780990600586s

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_env_sln-1.0.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_env_sln-1.0.7-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file json_env_sln-1.0.7.tar.gz.

File metadata

  • Download URL: json_env_sln-1.0.7.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for json_env_sln-1.0.7.tar.gz
Algorithm Hash digest
SHA256 a70a0637ce6b65172b4268246b166b3a87df19079c2acc5cc132e698200b84a6
MD5 1ae07ecfdc9bdab20f7b707a5e3aa53f
BLAKE2b-256 25a6d7a67b65b80b88b0edc10ad1fd9a2947e5f7402dbf7c86e5071b24be8685

See more details on using hashes here.

File details

Details for the file json_env_sln-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: json_env_sln-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for json_env_sln-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b206f2cf544257064f92ee60a6a35dc7b10c7104a53d037dadc96c0397e6a37d
MD5 5d56eeb05b6ff4ac9e60778fddb29f5d
BLAKE2b-256 252dab45c8c597f8b5e5296ca20dc4594337a7e25fc2bc29e47d8306038270e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page