Skip to main content

Environment handling to simplify development environments

Project description

MIT License LinkedIn


Logo

KUNGFU.AI Env

Environment handling to simplify development environments

Table of Contents

Built With

Getting Started

This repo aims to be a cloud and local compatible approach to modern application environment handling.

Environment files committed with the repo bring us some clear advantages that we should consider when building software.

At KUNGFU.AI, many of our usecases are single container microservice deployment into a cloud. By committing secrets to cloud Secret Manager, and keeping Secret IDs + other environment data within our env files, we're able to:

  1. Keep our deployed assets secure
  2. Developers don't have to pass keys, know about keys, or share env files (YUCK)
  3. Developers can pull and run their repos immediately.

The kungfuai/env repo aims to simplify these use-cases.

Dependencies

Python 3.8

Installation

pip install kungfuai-env

How does it work?

The flow is 3 steps - Construction, Registration, and Loading. e.g.

# Construction
env = Environment('src/env')
# Registration
env.register_environment("test")
env.register_environment("prod")
# Loading
env.load_env()

In the above example, Environment() is constructed, and the path to environment files is set to be located at src/env.

Next, we state that we have a test environment, and a prod environment that we intend to load. The names are important - seeing test indicates that env.load_env() will seek a .test.env file in the src/env directory. The same would be true for prod / .prod.env

Runtime Environment Selection

Now, we know how to handle the environments. How do we know which ones to load when the application starts?

There is a special environment variable that we always watch named ENV.

With the above example in mind, if you set ENV=PROD or ENV=prod, you will load the .prod.env file.

If you set ENV=TEST or ENV=test, you will load the .test.env file.

If you do not set anything for ENV, you will load, by default, the .local.env file.

Usage

Simple Example

In the most simple of applications, imagine a main.py with a .local.env environment

# main.py
import os
from kfai_env.env import Environment

if __name__ == "__main__":
    print("Simple Python App Example")

    e = Environment()
    e.register_environment("prod")
    e.load_env()
    print(os.getenv("TEST_ENV"))
# .local.env
TEST_ENV=HELLOWORLDFROMLOCAL
# .prod.env
TEST_ENV=HELLOWORLDFROMPROD

If we were to run python3 main.py with this above example program, we would see HELLOWORLDFROMLOCAL. If we were to run ENV=PROD python3 main.py, we would see HELLOWORLDFROMPROD.

Roadmap

See the open issues for a list of proposed features (and known issues).

  1. Upgrade project to use poetry as the build and deploy system (instead of pip + versioneer)

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Endurance Idehen - endurance.idehen@kungfu.ai

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

kungfuai-env-0.2.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

kungfuai_env-0.2.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file kungfuai-env-0.2.3.tar.gz.

File metadata

  • Download URL: kungfuai-env-0.2.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for kungfuai-env-0.2.3.tar.gz
Algorithm Hash digest
SHA256 8e20a0a1f061fe067fd9f1b1f7a603a275d42d3a39c8984d1dae362180ca65db
MD5 08053fed2a8b6ce400e6509db069a7d7
BLAKE2b-256 fc489f2318d8e30281abddbd0f2029b97c01737a935e2406af65a93f068ceca8

See more details on using hashes here.

File details

Details for the file kungfuai_env-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: kungfuai_env-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for kungfuai_env-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 61c4239290359fe76aeb6f00ca057846538520f54a73a5f6e17b532f52b734d4
MD5 4de30d86f401f921db761166adfa6e54
BLAKE2b-256 6bff22b0eaf0c3d68e63fa60c8b676a8831c7e03dd0376cce5a03206a2b42bef

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