Skip to main content

Remote env for python

Project description

pyremoteenv

pyremoteenv is a lightweight Python library designed for managing and distributing environment variables across microservices using remote configurations. This makes it ideal for cloud-native distributed systems where environment consistency and synchronization across services are critical.


Features

  • Centralized Environment Management: Seamlessly distribute environment variables to microservices via ZooKeeper or other remote backends.
  • Improved Consistency: Ensure distributed services share consistent configuration without manual intervention.
  • Bulk Operations: Manage multiple environment variables at once with simple APIs.
  • Pluggable Backend: Currently supports ZooKeeper, with potential for adding new backends.
  • Error Resilience: Handles common errors like missing nodes or network splits gracefully.

TODO

  • More backends: plain text, json, firebase
  • Watching mechanism to interact or inject new values immediately

Installation

Install pyremoteenv using pip:

pip install pyremoteenv

The only supported backend is ZooKeeper. Install dependencies for it

pip install pyremoteenv[zk]

Requirements

  • Python 3.8+
  • kazoo - For ZooKeeper support.

Usage

Example 1: Upload your config to remote storeage

This demonstrates how to push environment variables for multiple services to ZooKeeper.

from remoteenv import Env


# Example set of variables to distribute across services
# Add path prefixes to customize separated services by name, host, etc
s = """
DATABASE_DEFAULT_HOST=h2
service_1/DATABASE_DEFAULT_HOST=h3
service_1/host_4/DATABASE_DEFAULT_HOST=h1
"""

# Split the variables into key-value pairs
def split_text(text):
    for line in text.split('\n'):
        line = line.strip()
        if not line:
            continue
        yield tuple(line.split('=', 1))

variables = list(split_text(s))

env = Env('zk', settings={'prefix': 'test', 'hosts': 'zookeeper:2181'})
with env:
    env.set_many(variables)

Example 2: Read all remote variables including path prefixes

Retrieve and display all stored variables, including their paths.

with env:
    for k, v in env.dump():
        print(f"{k}={v}")

Example 3: Read remote config

with env:
    print("Read using variable name...")
    path = 'DATABASE_DEFAULT_HOST'
    v = env.get(path)
    print(f"{path}={v}")  # Example: DATABASE_DEFAULT_HOST=h2

    print("Reading with path filters...")
    variables_remote = {}
    for k, v in env.get_many('service_1/*', 'host_4/*', 'service_1/host_4/*'):
        # Find the most suitable key 
        variables_remote[k] = v
    print(variables_remote)

Documentation

Full documentation and advanced usage examples are available at the GitHub repository.


Contributing

Contributions are welcome! If you'd like to enhance the functionality or fix issues, kindly follow these steps:

  1. Fork the repository on GitHub.
  2. Clone your fork:
    git clone https://github.com/Romamo/pyremoteenv.git
    
  3. Make your changes and test them.
  4. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.


Support

If you encounter any issues or have questions, feel free to open an issue on the GitHub Issues Page.

Happy coding! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyremoteenv-0.2.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyremoteenv-0.2.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pyremoteenv-0.2.2.tar.gz.

File metadata

  • Download URL: pyremoteenv-0.2.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.13

File hashes

Hashes for pyremoteenv-0.2.2.tar.gz
Algorithm Hash digest
SHA256 653d4633b7f249be0516bdeb37ac0e081e1650b90a31defcbec10676e994b003
MD5 4dbfa40df5da0ce90b3f0461c5e91803
BLAKE2b-256 d1b457757673743d4f6db3396afef428c29b672a2da8799c1964294f39dfae8d

See more details on using hashes here.

File details

Details for the file pyremoteenv-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyremoteenv-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.13

File hashes

Hashes for pyremoteenv-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6eaaed4a4300f1eba3ede3adc06e1f3996739f0716c3c5d1cbd51cf712eb8e77
MD5 51444ffb63ec0020557f54ca7084b058
BLAKE2b-256 f299063174da30956e52862ee689c46b490e1719970ac481dda0326d4b9553f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page