IGitt.Utils package

Module contents

Provides useful stuff, generally!

class IGitt.Utils.Cache[source]

Bases: object

A class to manage cache with IGitt and any other external application.

The cache mechanism should be able to process raw JSON data. The response data from external requests is stored in the cache with the API URL of the associated IGitt object as the key and the data is stored along with its entity tag header, which is used alongside If-None-Match header for further queries using conditional requests. When an incoming webhook is received, the timestamp of reception is cached and any queries later on the same URL use the If-Modified-Since HTTP Header and the reception time using conditional requests, since the ETag Header is no longer valid. Note that conditional requests do not add up to rate limits on APIs.

To use IGitt’s caching mechanism for external request management, simply add the following code to your application before using IGitt.

>>> from IGitt.Utils import Cache
>>> Cache.use(read_from, write_to)

If not provided, IGitt uses a default in-memory cache. For further details follow the specific method documentation below.

classmethod get(key) → Optional[dict][source]

Retrieves the entry from cache if present, otherwise None.

classmethod set(key, item)[source]

Stores the entry in cache.

classmethod update(key, new_value)[source]

Updates the existing entry with new data, if present, otherwise creates a new entry in cache.

classmethod use(read_from: Callable, write_to: Callable)[source]

Connects the cache read, write functions to Cache class.

  • read_from – The method to be called to fetch data from cache. It should be able to receive only one parameter, key, which is used to identify an entry uniquely in the cache.
  • write_to – The method to be called to write data to cache. It should be able to receive two parameters, key (used to identify the entry in cache) and the item to be stored in cache, in the specified respective order.
classmethod validate(item: dict) → dict[source]

Checks if the given item has valid data and adds missing fields with default values. Expected fields are as follows.

Returns:The item dictionary after validation without any missing fields. Also removes any additional unrelated fields from the given dictionary.
Raises:TypeError, if the field does not match the expected type. ValueError, if the type is correct, but the value is invalid.
class IGitt.Utils.CachedDataMixin[source]

Bases: object

You provide:

  • self._get_data for getting your data

You can also create an IGitt instance with your own data using from_data classmethod.


Retrieves the data, if needed from the network.

default_data = {}
classmethod from_data(data: Optional[dict] = None, *args, **kwargs)[source]

Returns an instance created from the provided data. No further requests are made.

Raises:TypeError – When the args provided are insufficient to call __init__.

Refreshes all the data from the hoster!

class IGitt.Utils.LimitedSizeDict(*args, **kwargs)[source]

Bases: collections.OrderedDict

LimitedSizeDict pops items from the first if the size of dictionary exceeds the specified limit.

class IGitt.Utils.PossiblyIncompleteDict(data: dict, refresh)[source]

Bases: object

A dict kind of thing (only supporting item getting) that, if an item isn’t available, gets fresh data from a refresh function.


Returns the stored data.


Refresh if it may need a refresh.


Refreshes data unconditionally.

update(value: dict)[source]

Updates the dict with provided dict.


Remove None values from dict