Skip to main content

Varenv

current :green_heart: license python

A simple way to mock your environment variables during development.

Just add'em to the varenv.conf.json and have fun =). The varenv package will not overwrite any already existente environment variables.

This library was designed to be inbuilt in pojects that, when going to production, will consume environment variable, very commonly used in application that'll run in docker containers. So, they need something to mock these variable under development but that won't get in the way in production.


Basic Usage

Create a file called varenv.conf.json at your project's root path like this:

{
  "SRPC_SERVER": "127.0.0.1",
  "SRPC_SERVER_PORT": "2727",
  "ANY_OTHER_VARIABLE_I_DESIRE": 567865
}

It can also be YAML file called varenv.conf.yml or varenv.conf.yaml. The equivalent to the above file being:

SRPC_SERVER: 127.0.0.1
SRPC_SERVER_PORT: '2727'
ANY_OTHER_VARIABLE_I_DESIRE: 567865

now use it like this in your program:

import varenv.varenv as varenv

my_server_ip = varenv.get_env("SRPC_SERVER")
my_server_port = varenv.get_env("SRPC_SERVER_PORT")

# after a while, for some reason, something chaged your enviroment variables values
# then refresh it
varenv.refresh()
new_server_port = varenv.get_env("SRPC_SERVER_PORT")

If you want to change the location of the virenv.conf.json file, you can define a environment variable called VARENV_CONF_FILE_PATH to any path you desire.

You can do that in a variaty of ways, here is two exemples:

by python:

import os
os.environ['VARENV_CONF_FILE_PATH'] = '/folder/my_path/virenv.conf.json'
import varenv

by your .bashrc file:

VARENV_CONF_FILE_PATH=/folder/my_path/virenv.conf.json

by bash when calling your python program:

VARENV_CONF_FILE_PATH=/folder/my_path/virenv.conf.json python3 my_program.py


Author's Note

create by me, davincif, this project was first though to fulfill the needs of a another professional project I've made. But it sounds so potentially useful the the community that I decided to open this package here freely distributed.

I actively use this project since I created it back in 2018, and it happens to be pretty useful. Wich is surprising given that I thought it would be a one project thing. Thus I decided keep maintaining it, basically by solving bugs and adding new features required by other projects.

So let me know if you want to help out, or if you need any formal concentiment to use this software, despite the fact that it's already free and open by terms of a very permissive license as zlib.


See also
  • Dependency Manager project: A simple way of managing pip dependencies, separating in dev and prod, and tracking them.
  • SimplestRPC project: A simple RPC for python - study project.

Metadata

Release files for varenv 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for varenv 1.0.7
File Size Uploaded
varenv-1.0.7.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for varenv 1.0.7
File Interpreter ABI Platform
varenv-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / varenv-1.0.7.tar.gz

Download URL varenv-1.0.7.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
56e90df0b1320520acd849435975cff40ce864d15a875b6a49e35c6394a2805b
BLAKE2b-256 checksum
How to use checksums
14d2ff78782c0724f6a26e78df78be6bf74a47ec18dc3d6d04ffc3a006eb67b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.0

Release files / varenv-1.0.7-py3-none-any.whl

Download URL varenv-1.0.7-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a2e6946bf4ffdd83ac50338b1e884a635ae7a93c950eec8c0b6b37336506145
BLAKE2b-256 checksum
How to use checksums
9ff59e9eb54eff98baa643b1eb6145098f0f8c0e6b681eede655674b21388ede
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page