question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Load multi environment settings from dictionary

See original GitHub issue

I have researched documentation and also some source code, but I can’t find any possibility to load configuration from a dictionary. I need this for testing, as we define settings in the test code itself. Generally it would be good to have a wrapper where everything smart and environment dependent is disabled (I know about DynaconfDict, but this doesn’t quite fulfill my needs), especially the dependency on files and env vars as those can cause quite a few issues as I experienced.

Up to now i used DotMap to achieve similar interface, but at nested levels merging is becoming an issue, thus I’m now trying to decrease prod / test parity by also applying dynaconf in tests.

I am aware that it I can just pass the dict like Dynaconf(**json_config), but this results in issues with environments and so on.

Am I missing an option?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hoermannpaulcommented, Oct 12, 2021

I just fund a workaround, which is definetly not nice but does what I need:

from dynaconf import Dynaconf
from dynaconf.loaders import json_loader
from dynaconf.loaders.base import BaseLoader


def load(obj, env=None, silent=True, key=None, filename=None):
    class CustomLoader(BaseLoader):
        def load(self, filename=None, key=None, silent=True):
            # settings as dict from outer scope
            self._load_all_envs({"asdf.json": settings}, silent, key)

    loader = CustomLoader(
        obj=obj,
        env=env,
        identifier="json",
        extensions=None,
        file_reader=None,
        string_reader=None,
    )
    loader.load(
        filename=filename,
        key=key,
        silent=silent,
    )

json_loader.load = load

settings = Dynaconf(settings_file="settings.json", loaders=[], environments=True)

Vulnerable to internal interface changes though.

0reactions
stale[bot]commented, Jun 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Load multi environment settings from dictionary #674
I am aware that it I can just pass the dict like Dynaconf(**json_config) , but this results in issues with environments and so...
Read more >
Load balancing settings - Saptechnicalguru.com
Load balancing settings. Load balancing. Larger productive systems have multiple application servers to spread the workload.
Read more >
RFC 7019 - Application-Layer Multicast Extensions to ...
1. Peer that initiates multicast group: group_id = create(); // Allocate a unique group_id. // The root is the nearest // peer in...
Read more >
Configuration — Sanic 20.12.3 documentation - Read the Docs
There are several ways how to load configuration. From Environment Variables¶. Any variables defined with the SANIC_ prefix will be applied to the...
Read more >
REsource LOcation And Discovery (RELOAD) Base Protocol
NAT Traversal: RELOAD is designed to function in environments where many, ... A usage may define multiple Kinds of data that are stored...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found