Search code examples
memgraphdb

How to read Memgraph process environment variables from a query module?


I'm developing a query module. I need to use some environment variables. I want to configure the module without hardcoding values inside the module. What can I do? I'd like to avoid reading values from external text files.

Is there a way to access Memgraph ENV variables?


Solution

  • In Memmgraph query modules have access to the Memgraph's environment variables. Here is the code that you can use for testing:

    import mgp
      
    import os
      
    home = os.getenv("HOME")
    my_env = os.getenv("MY_ENV_VAR")
      
    @mgp.read_proc
    def procedure() -> mgp.Record():
        print(my_env)
        print(home)
        return mgp.Record()