Skip to main content

An extension of python's native dictionary class, that implements volatile sets.

Project description

Volatile Sets Dictionary

This project aims to extend python's native dictionary class, in order to add volatile sets. Volatile sets are a combination of key and value that expires after a period of time. This time is decided by the user.


Instalatiton

You can install it using pip with the following command.

pip install volatile_dictionary

To install it by cloning its github repository, use the following commands. The "-e" flag install it in the path you clone it to, so, changes in the code will be instantly valid for the package users.

git clone https://github.com/pedrogyrao/volatile_dictionary
cd volatile_dictionary
pip install -e .

Using the VolatileDictionary Class

First import it in your project:

from volatile_dictionary import VolatileDictionary

Then instantiate it:

volatile_dict = VolatileDictionary()

VolatileDictionary works as a normal dictionary

volatile_dict['key'] = 'value'
print(volatile_dict['key'])

saves internally the set "{'key', 'value'}" and outputs:

value

This set added above is nonvolatile. To add a volatile the key must be a length 2 tuple and with the second element being the set's duration time in seconds.

volatile_dict['volatile_key', 2] = 'volatile_value'

for the 2 seconds after the above line is ran, this code

print(volatile_dict['volatile_key'])

will output:

volatile_value

after 2 seconds the set "{'volatile_key': 'volatile_value'}" will be deleted.


To manipulate this volatile sets three methods were created:

  • is_set_volatile(key): returns "True" if the set is volatile and "False" if the set is nonvolatile.
  • get_set_lifetime(key): returns the remaining lifetime of the specified key. If the key doesn't represent a volatile set, the method raises "NonvolatileTypeError".
  • cancel_volatily(key): cancel the volatility of a volatile set. If the key doesn't represent a volatile set, the method raises "NonvolatileTypeError".

In order to work with this differentiation between volatile and nonvolatile sets, the basic dict methods "keys", "values" and "items" were implemented too:

  • volatile_keys and nonvolatile_keys;
  • volatile_values and nonvolatile_values;
  • volatile_items and nonvolatile_items.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

volatile_dictionary-0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

volatile_dictionary-0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file volatile_dictionary-0.1.tar.gz.

File metadata

  • Download URL: volatile_dictionary-0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5rc1

File hashes

Hashes for volatile_dictionary-0.1.tar.gz
Algorithm Hash digest
SHA256 d4b70d01e862261ce06297680212c2d679277f0808d3a132b2f846d5e4249a97
MD5 d0fc566a8e11bebbe32dd2d7bd0ccf28
BLAKE2b-256 cfdc5819af1ab43d9baa903b2a5443f425969f6bfc717673e747ec489b64d8ad

See more details on using hashes here.

File details

Details for the file volatile_dictionary-0.1-py3-none-any.whl.

File metadata

  • Download URL: volatile_dictionary-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5rc1

File hashes

Hashes for volatile_dictionary-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eab1df240fdda9f5ceb1e9799e20d067aa71b7c3c4c8d403dce9e89823872a75
MD5 a7df540270acf83bd24e44606412457d
BLAKE2b-256 1dd6e0c69b91deaad64246c640719669e022e6183143fc57211f4a99ec10988f

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