Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add additional values from file #224

Open
thmsklngr opened this issue Aug 3, 2022 · 3 comments
Open

Feature request: add additional values from file #224

thmsklngr opened this issue Aug 3, 2022 · 3 comments

Comments

@thmsklngr
Copy link

Hi,
I'm really happy that I found your excellent package, it makes my life a lot easier. One thing I may miss is the possibility to load extra attributes from a file into an existing instance.

Example:
I load a main configuration file and want to add additional configuration values from a plugin configuration file into the same Box instance. I created a much smaller solution myself, where I added a function add_from_file and instead of creating of a new instance I simply updated the existing one with the values coming from the second file.

This may be easier than creating two independent instances and then updating the first one with the values from the second one.
What do you think?

Regards, Thomas

@cdgriffith
Copy link
Owner

Hey Thomas,

Thanks for the idea, only issue is that I am having a hard time following what you really want. (My brain is scrambled between what you mean between attribute / value / configuration file.)

Could you provide a simplified code example of what you have to do now and how you would like it to behave?

Much appreciated!

@thmsklngr
Copy link
Author

Ok, I'll try to explain it a bit better. I hope that I can do that, I'm not English native. :)

First I try initialize a new Box instance by getting - lets say - default values from a configuration file:

>>> config = Box.from_yaml('/path/to/my/default/config.yml')
>>> print(config)
{'key1':'value1','key2':'value2', ...}

Then, further on, I'd like to load additional values from another configuration file, maybe for a plugin. Of course, I could to that by reading the additional values to its own Box instance and update the first one:

>>> config2 = Box.from_yaml('/path/to/my/plugin/config.yml')
>>> print(config2)
{'foo':'bar', 'baz':'gus', ...}
>>> config.update(config2)
>>> print(config)
{'key1': 'value1', 'key2': 'value2', 'foo': 'bar', 'baz': 'gus'}

The main idea behind my feature request now is to skip creating an additional instance and load the additional values directly to the first instance:

>>> config.additional_values_from_yaml('/path/to/my/plugin/config.yml')  # name of function picked randomly :)
>>> print(config)
{'key1': 'value1', 'key2': 'value2', 'foo': 'bar', 'baz': 'gus'}

Configuration files are just an example, I deal a lot of it with them.

I hope it's now clear what I mean. :)

Regards, Thomas

@justquick
Copy link

please checkout dynaconf which uses this project for their configuration storage

https://www.dynaconf.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants