Implementing Arian's kv as pure Python