Authentication

The codePost API uses API keys. You can view and manage your API key from your codePost settings page.

Your API key carries the same privileges as your codePost username and password, so it can read and write data to any course in which you are listed as a Course Admin. Please make sure to keep it secure! Do not share your API key in publicly accessible spaces such as GitHub or client-side code. If you believe your API key has been compromised, you can reset your token from your codePost settings page. Doing so will invalidate your old token, so requests made with the old token will fail.

All API requests must be made over HTTPS. Calls made over HTTP (which can reveal secret contents, such as your API key) will always fail.

# Install with "pip install codepost"
import codepost

# Setup your API key for all subsequent calls:

# Option 1: Hard-coding your API key in your source code
codepost.configure_api_key(api_key="<YOUR API KEY>")

# Option 2: Using the CP_API_KEY environment variable
import os; os.environ["CP_API_KEY"] = "<YOUR API KEY>"
codepost.configure_api_key()

# Option 3: Using the codePost configuration file
with open(".codepost-config.yaml", "w") as config_file:
  config_file.write("api_key: <YOUR API KEY>")
codepost.configure_api_key()