Skip to main content

Package allowing to share variables, configurations and counters between dependencies

Project description

Sharing

A library to share variables and configurations between modules of a same project and managing their effects.

Goal

When working on a big project composed of multiple packages, you sometime needs to access to common variables and configurations from your different packages.

This library objectives are :

  1. To create a shared in memory variables repository usable between your packages. No database, network or disk access required.
  2. Allowing hooks registration to trigger function on shared variable update. The variable update from library A can have a direct impact on the library B and the hook allow to automatically trigger a registered function in B when the update occurred in A.

Install

Recommended install

Install using pip from pypi.org

pip install sharing

Install from sources

Clone the repository and install:

git clone http://gitlab.guirimand.eu/tguirimand/sharing.git
cd sharing
pip install -e .

Using the library

The package contains 3 variables grouper:

  • sh.shared: to share generic variables
  • sh.config: to share specific variables used in configuration
  • sh.counters: to share counters (integers only)

Sharing a variable between two packages :

From package A:

import sharing as sh

my_variable = 12345
sh.shared.set('variable tag', my_variable)  # Creating the shared variable

From package B:

import sharing as sh

my_variable = sh.shared.get('variable tag')  # None if it doesn't exists
sh.shared.set('variable tag', my_variable + 1)  # Updating the shared variable

Creating a hook

A hook can be created using a decorator. To run the function fu every time the shared variable using the "bar" tag is updated:

@sh.shared.updatable(key="bar")
def fu():
    if sh.shared.get('bar')==3:
        print("bar has now the value 3")
    else:
        print("bar has been updated")

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

sharing-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

sharing-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file sharing-0.1.0.tar.gz.

File metadata

  • Download URL: sharing-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for sharing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a269991b46211018f6ed9aaa776d79d31d82758d562f32e97ff5657cb153e08
MD5 16143b2ae8bba6e54b0841c48ddf71af
BLAKE2b-256 d61fbf739d082a753d34e8c5c15b3e47c9c13127d9f10976e6fb43518ee128b1

See more details on using hashes here.

File details

Details for the file sharing-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sharing-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for sharing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f9f65d3a8e88cc805b11cabb04bd00968391f204b8575c20db33fb68fe01f1b
MD5 d337ff3f60247084d7a1d640e0e2fe09
BLAKE2b-256 79ee3c0dfdc8962f76e192d2813529f703b8aee925670646d3c83dd09ce63c78

See more details on using hashes here.

Supported by

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