Skip to main content

autokattis

Updated Kattis API wrapper as of May 2023 after the major UI/UX change.

Setup

Simply install it as a Python package.

$ pip install autokattis

Use Cases

For now, this package supports OpenKattis and NUSKattis.

Login

Construct an OpenKattis object that takes in the username and the password.

from autokattis import OpenKattis
kt = OpenKattis('username', 'password')
kt = OpenKattis('username') # which will then prompt you for the password

where 'username' is your Kattis username/email and 'password' is your Kattis account password. Both should be provided as Python strings.

Tagged status messages can be muted or enabled globally with set_verbose:

from autokattis import OpenKattis, set_verbose

set_verbose(False) # mute [login], [database], and API status messages
kt = OpenKattis('username', 'password')
set_verbose(True)  # enable them again

Similarly if you want to login to NUS Kattis.

from autokattis import NUSKattis
kt = NUSKattis('username', 'password')
kt = NUSKattis('username')

OpenKattis

Due to backwards compatibility, you can still use Kattis as a shorthand form of OpenKattis.

Problem-specific

kt.problems()                               # problems you have solved so far
kt.problems(show_partial=False)             # exclude partial submissions
kt.problems(low_detail_mode=False)          # include more data for each problem
kt.problems(*[True]*4)                      # show literally all problems on Open Kattis

kt.plot_problems()                          # plot the points distribution
kt.plot_problems(filepath='plot.png')       # save to a filepath
kt.plot_problems(show_partial=False)        # plot fully solved submissions

kt.problem('2048')                          # fetch info about a problem
kt.problem(['2048', 'abinitio', 'dasort'])  # fetch multiple in one
kt.problem({'2048', 'abinitio', 'dasort'})  # tuples or sets also allowed
kt.problem('2048', download_files=True)     # download files too

kt.stats()                                  # your best submission for each problem
kt.stats('Java')                            # all your Java submissions
kt.stats(('Python3', 'Cpp'))                # multiple languages

kt.suggest()                                # what's the next problem for me?
kt.achievements()                           # do I have any?
kt.problem_authors()                        # list down all problem authors
kt.problem_sources()                        # list down all problem sources

Ranklist

kt.ranklist()                                                           # people around you

kt.user_ranklist()                                                      # top 100 users in general ladder
kt.challenge_ranklist()                                                 # top 100 users in challenge ladder

kt.country_ranklist()                                                   # top 100 countries
kt.country_ranklist('Singapore')                                        # specific country
kt.country_ranklist('SGP')                                              # use country code instead

kt.affiliation_ranklist()                                               # top 100 affiliations
kt.affiliation_ranklist(affiliation='National University of Singapore') # specific affiliation
kt.affiliation_ranklist(affiliation='nus.edu.sg')                       # use affiliation domain instead

NUSKattis

Problem-specific

kt.problems()                               # problems you have solved so far, only supports low detail mode
kt.problems(show_solved=False)              # show literally all problems on NUS Kattis

kt.problem('2048')                          # fetch info about a problem
kt.problem(['2048', 'abinitio', 'dasort'])  # fetch multiple in one
kt.problem({'2048', 'abinitio', 'dasort'})  # tuples or sets also allowed
kt.problem('2048', download_files=True)     # download files too

kt.stats()                                  # your best submission for each problem
kt.stats('Java')                            # all your Java submissions
kt.stats(('Python3', 'Cpp'))                # multiple languages

Course-specific

kt.courses()                                    # current and recently ended courses
kt.offerings('CS3233')                          # course offerings
kt.assignments('CS3233_S2_AY2223')              # offering assignments but course ID not provided
kt.assignments('CS3233_S2_AY2223', 'CS3233')    # offering assignments

Convert to DataFrame

As simple as adding .to_df()!

kt.problems().to_df()
kt.ranklist().to_df()

Other Scenarios

Some scenarios you can perform when using autokattis:

  1. Mapping problem ID with its difficulty
    okt = OpenKattis(...)
    df = okt.problems().to_df()
    diff_map = dict(zip(df.id, df.difficulty))
    
  2. Find the number of questions on every assignment on an NUS course offering
    nkt = NUSKattis(...)
    df = nkt.assignments('CS3233_S2_AY2324').to_df()
    df['n_problems'] = df['problems'].apply(lambda x: len(x.split(',')))
    df[['name', 'n_problems']]
    
  3. Find the average difficulty of every assignment on an NUS course offering
    diff_map = ... # see scenario 1
    
    nkt = NUSKattis(...)
    avg_2dp = lambda x: round(sum(y:=[v for v in x if v != None])/max(len(y), 1), 2)
    df = nkt.assignments('CS3233_S2_AY2324').to_df()
    df['avg_diff'] = df['problems'].apply(lambda x: avg_2dp(map(diff_map.get, x.split(','))))
    df[['name', 'avg_diff']]
    
  4. Group top 100 users by country
    okt = OpenKattis(...)
    okt.user_ranklist().to_df().groupby('country').size()
    

More Information

The docstrings might be a great help if you want to know more about the JSON return values!

from autokattis import OpenKattis
help(OpenKattis)

Testing

The test directory is provided within this repository. You are free to test autokattis with these anytime.

>>> python test/openkattis.py
...
>>> python test/nuskattis.py
...

Useful References

Contributing

Feel free to suggest anything or add on some implementation by simply creating a pull request!

Metadata

Release files for autokattis 2.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autokattis 2.1.7
File Size Uploaded Provenance Actions
autokattis-2.1.7.tar.gz 36.0 kB Without provenance Details for autokattis-2.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for autokattis 2.1.7
File Interpreter ABI Platform Actions
autokattis-2.1.7-py3-none-any.whl Python 3 none any Details for autokattis-2.1.7-py3-none-any.whl

Total release size: 72.9 kB

Release files / autokattis-2.1.7.tar.gz

Download URL autokattis-2.1.7.tar.gz
Size 36.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c939de7988af57a7c8be0d861596585f23269d267fae4e70e07c04dcedadb4b8
BLAKE2b-256 checksum
How to use checksums
a26ed5472e5bf7df13d0353a3142b20dc3c0d18aa69055ec51c87a99024bb100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / autokattis-2.1.7-py3-none-any.whl

Download URL autokattis-2.1.7-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
902f89b85ba6c14406e78d1b75d532f71d24fafe8f16529cc5b649c9628c08a4
BLAKE2b-256 checksum
How to use checksums
a17fc1aab607ffb6d48452ef966a67d9fcf02a79c728e42855cd88ea66a40ae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for autokattis 2.1.7

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.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page