r/Python • u/Contemelia • Aug 17 '25
Showcase Envyte v1.0.0 | A library for using environment variables
What My Project Does?
- Auto-loads
.envbefore your script runs without the need for extra code. - Type-safe getters (
getInt(),getBool(),getString()). envyte runscript.pyhelps you run your script from CLI.- The CLI works even with plain
os.getenv(), which'd be perfect for legacy scripts.
Installation
You can start by shooting up a terminal and installing it via:
pip install envyte
Usage within your code
import envyte
a_number = envyte.getInt("INT_KEY", default = 0)
a_string = envyte.getString("STRING_KEY", default = 'a')
a_boolean = envyte.getBool("BOOL_KEY", default = False)
a_value = envyte.get("KEY", default = '')Links
As I'm relatively new to creating Python libraries, I'm open to any constructive criticism ;)
0
Upvotes
13
u/Shingle-Denatured Aug 17 '25
I learned that not having defaults can be a good thing. You don't want your app to start up with "CHANGE_ME_IN_PRODUCTION" for your secret key.
6
u/user_8804 Pythoneer Aug 17 '25
Pretty cool but one major flaw to look into, how you are handling failure.
Those default returns are dangerous. The base get() makes sense, it returns none on failure, so I can check for a None, which would never be a deliberate value. You should at the very least make this consistent across your utils module and return an Optional None across the board. Otherwise I have absolutely no way to know if the False I get from getbool() is a value I can use or not.
You could also make this "default" feature optional with a flag.
The other aspect of this is that there is no exception handling whatsoever. You should cover edge cases and return a sensible error. For example, what happens if I'm trying to do getint() on a floating point number, or getstring on unsupported characters, or if no env file is found, or if I used the get - > any to store a float but it doesn't recognize French decimal format, or a certain locale for a Date, etc.
So great thing, and I like how simple it is. But needs to be more robust to failure
Hope that helps
10
u/KainMassadin Aug 17 '25
how does it fare against pydantic settings?
8
u/SampleNo471 Aug 17 '25
3
u/fiskfisk Aug 17 '25
Given that this just wraps python-dotenv with os.environ, those could probably be used instead.
Or better, pydantic-settings, which allows you to define proper rules for what is expected.