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.3.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.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyremoteenv-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 1c1e0909f945fc4ea4c23c5e29d170d981ce61225692608946bfeaf18b18e176
MD5 660ffb4e9cd8efafd1a4e321a3e995b1
BLAKE2b-256 2ecdb2f98fc622a688ddf7805b57eb398934379afbc677f1ec4e2440b90b95c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyremoteenv-0.2.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a9df066d7687708459c272d767284e8baec4875b4776df89a9afe45e1c9bab5b
MD5 bb02fb8b592b04b0fed160165cc97562
BLAKE2b-256 5f434c132bbc279ce47a6875f7894e48de3ff2ad77b0ff34f0b71430036f23a4

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