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.4.tar.gz (7.1 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.4-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyremoteenv-0.2.4.tar.gz
  • Upload date:
  • Size: 7.1 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.4.tar.gz
Algorithm Hash digest
SHA256 b52cbc3c59265c6e7a02521b4f9c364871c16400717722361f569cfa38aebbd4
MD5 e4cfaafc107bb7d3de25ed46e1008bcf
BLAKE2b-256 e0fbcd0beb1338b7252b36798977031d4b1583be9c385e3a4a75d45525e3089b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyremoteenv-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2767825c383016dcd3422ebe9c2e516a06a389f064552da0a7c17d3e3fb00472
MD5 e77e18de85b8dc630f281c7d9e5c489c
BLAKE2b-256 4450d9841ee20b5dba9ea7e1ba35a86530e8e3d19fb31210ab586db31ab2d5e2

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