Key

Safely parsing keys for submission.

Numerai authentication is done by passing a valid pub_id and secret_key for the numerapi API.

As stakes get larger we might want additional protection and confidence that credentials are parsed correctly. We might also like to load credentials from a (JSON) file that is stored safely somewhere. This section offers tools to safely load and use Numerai credentials.

A Key object is needed to initialize submission objects.

The Key object allows you to either initialize from Python variables (strings) or load from a JSON file.

In order to load_key_from_json, the key JSON file must have the following format:

{"pub_id": "PUBLIC_ID", "secret_key": "SECRET_KEY"}

source

load_key_from_json

 load_key_from_json (file_path:str, *args, **kwargs)

Initialize Key object from JSON file.

Credentials file must have the following format:

{"pub_id": "PUBLIC_ID", "secret_key": "SECRET_KEY"}


source

Key

 Key (pub_id:str, secret_key:str)

Numerai credentials.

Example usage 1: direct initialization

# Random credentials
pub_id, secret_key = "QVdFU09NRV9QVUJMSUNfSUQ=", "VkVSWV9FVkVOX01PUkVfU0VDUkVUX0tFWQ=="
example_key = Key(pub_id=pub_id, secret_key=secret_key)
assert (example_key.pub_id, example_key.secret_key) == (pub_id, secret_key)

Example usage 2: loading from JSON

example_key2 = load_key_from_json("test_assets/test_credentials.json")

This Key contains the credentials defined in test_assets/test_credentials.json.

assert (example_key2.pub_id, example_key2.secret_key) == (
    "UFVCTElDX0lE",
    "U1VQRVJfU0VDUkVUX0tFWQ==",
)