khan_api_wrapper (Python 3 Wrapper for Khan Academy API)
About
This is a simple implementation of using the Khan Academy API with python. It uses the alternative method of logging in with your own account, and should be sufficient if you are only looking to retrieve data from your students.
Requires
- requests
- rauth
Set up:
Install:
$ pip install khan_api_wrapper
Register your app with Khan Academy, to get the necessary tokens. That is it, you should now be able to use the wrapper in your python script.
General use:
test in an interactive shell:
$ python
> from khan_api_wrapper.khan import KhanAcademySignIn, KhanAPI
>
> consumer_key = "Key from registering app"
> consumer_token = "Token from registering app"
> khan_identifier = "username_of_account_used_to_register_app"
> khan_password = "password_of_account_used_to_register_app"
> kauth = KhanAcademySignIn(consumer_key, consumer_token, khan_identifier, khan_password)
> token, secret = kauth.authorize_self()
>
> kapi = KhanAPI(consumer_key, consumer_token, token, secret)
> kapi.user() # should print your user data to console.
>
> # Use your own endpoint
> kapi.get("/api/internal/user/missions") # should show your missions
Examine khan.py for all the available methods or example.py for ideas on how to use in your application.
Token freshness:
Through trial I have discovered that the access token and secret are valid for 2 weeks. So you may consider storing them in a separate file or database, and write a function to only fetch tokens if they are expired.
def get_tokens():
# fetch token data from saved json file
with open("tokens.json", "r") as f:
tokens = json.loads(f.read())
# check if tokens are expired
now = time.time()
if now - tokens["timestamp"] > 3600 * 24 * 14:
kauth = KhanAcademySignIn(consumer_key, consumer_secret, token, uname, pwd)
token, secret = kauth.authorize_self()
# update file with new tokens and timestamp
with open("tokens.json", "w") as t:
t.write(
json.dumps({"token": token, "secret": secret, "timestamp": now})
)
# return fresh tokens
return token, secret
# tokens are still valid, so return them
return tokens["token"], tokens["secret"]
# Then use the function to ensure we only use fresh tokens when necessary
token, secret = get_tokens()
kapi = KhanAPI(consumer_key, consumer_secret, token, secret)
...
Metadata
Release files for khan-api-wrapper 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| khan_api_wrapper-0.0.18.tar.gz | 11.1 kB | Without provenance | Details for khan_api_wrapper-0.0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| khan_api_wrapper-0.0.18-py3-none-any.whl | Python 3 | none | any | Details for khan_api_wrapper-0.0.18-py3-none-any.whl |
Total release size: 22.5 kB
Release files / khan_api_wrapper-0.0.18.tar.gz
| Download URL | khan_api_wrapper-0.0.18.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e33ab00d0a5006a315e175d76b62009fc4d6e31443f513becd2d95e3bf6ca604
|
|
BLAKE2b-256 checksum How to use checksums |
4167145af798d012278ffe85a0fca989903f174d869b54d6161d507b83f10589
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Release files / khan_api_wrapper-0.0.18-py3-none-any.whl
| Download URL | khan_api_wrapper-0.0.18-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69178517c8da9aacaa9061a845fb95a402a5a397eea91f56d71a82e376da6e8d
|
|
BLAKE2b-256 checksum How to use checksums |
b9d4e5c9cfc2c3a60ad6e70da01c72eb02b495f04697486abde9652995ac9a29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Security for khan-api-wrapper 0.0.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.