pycassa.util – Utilities

A combination of utilities used internally by pycassa and utilities available for use by others working with pycassa.

pycassa.util.convert_time_to_uuid(time_arg, lowest_val=True, randomize=False)

Converts a datetime or timestamp to a type 1 uuid.UUID.

This is to assist with getting a time slice of columns or creating columns when column names are TimeUUIDType. Note that this is done automatically in most cases if name packing and value packing are enabled.

Also, be careful not to rely on this when specifying a discrete set of columns to fetch, as the non-timestamp portions of the UUID will be generated randomly. This problem does not matter with slice arguments, however, as the non-timestamp portions can be set to their lowest or highest possible values.

Parameters:
  • datetime (datetime or timestamp) – The time to use for the timestamp portion of the UUID. Expected inputs to this would either be a datetime object or a timestamp with the same precision produced by time.time(). That is, sub-second precision should be below the decimal place.
  • lowest_val (bool) – Whether the UUID produced should be the lowest possible value UUID with the same timestamp as datetime or the highest possible value.
  • randomize (bool) – Whether the clock and node bits of the UUID should be randomly generated. The lowest_val argument will be ignored if this is true.
Return type:

uuid.UUID

Changed in version 1.7.0: Prior to 1.7.0, datetime objects were expected to be in local time. In 1.7.0 and beyond, naive datetimes are assumed to be in UTC and tz-aware objects will be automatically converted to UTC.

pycassa.util.convert_uuid_to_time(uuid_arg)

Converts a version 1 uuid.UUID to a timestamp with the same precision as time.time() returns. This is useful for examining the results of queries returning a v1 UUID.

Parameters:uuid_arg – a version 1 UUID
Return type:timestamp
class pycassa.util.OrderedDict(*args, **kwds)

A dictionary which maintains the insertion order of keys.

A dictionary which maintains the insertion order of keys.

clear() → None. Remove all items from D.
copy() → a shallow copy of D
classmethod fromkeys(S[, v]) → New dict with keys from S and values equal to v.

v defaults to None.

items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
keys() → list of D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → list of D's values