Skip to main content

Python client for HackerRank API

Project description

PyPI license

hackerrank-sdk

An Unofficial Python Client for the HackerRank Code Checker API.

Use it as a code-compiler for any of the programming languages supported by hackerrank.

You will need an api-key to use the SDK.Get it here.

The code is Python 2, but Python 3 compatible.

Installation

Fast install:

pip install hackerrank-sdk

For a manual install get this package:

wget https://github.com/nikhilkumarsingh/hackerrank-sdk/archive/master.zip
unzip master.zip
rm master.zip
cd hackerrank-sdk-master

Install the package:

python setup.py install

Examples

from hackerrank.HackerRankAPI import HackerRankAPI

API_KEY = ''  #your API-KEY here

compiler = HackerRankAPI(api_key = API_KEY)

print compiler.supportedlanguages()     #prints a list of supported languages


source = '''print "hello"'''    #give your source code here

'''
Alternatively,you can copy existing files to source this way:
with open(file_name,'r') as f:
     source = f.read()
'''

result = compiler.run({'source': source,
                       'lang':'python'
                       })


print(result.output,result.time,result.memory,result.message)    #get different variables associated with the result

Testcases are passed as a list of strings.

Here is another example which shows how to give testcases to the compiler:

from hackerrank.HackerRankAPI import HackerRankAPI

API_KEY = ''  # Your API-KEY here

compiler = HackerRankAPI(api_key = API_KEY)

source ='''
N, M = map(int,raw_input().split())
for i in xrange(1,N,2):
    print (".|."*i).center(M,'-')

print "WELCOME".center(M,'-')
for i in xrange(N-2,-1,-2):
    print (".|."*i).center(M,'-')
'''

result = compiler.run({'source': source,
                       'lang':'python',
                       'testcases':["9 27"]
                       })

print(result.output[0])

Here is the output:

output

output

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hackerrank-sdk-1.2.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file hackerrank-sdk-1.2.1.tar.gz.

File metadata

File hashes

Hashes for hackerrank-sdk-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b849cd243dd1d84ba9b65c686355d1cd67cd57bc4a7a7d303fdbc825423d2182
MD5 6c5042fedaa07283e7364def54c3afd5
BLAKE2b-256 ffa448b7e65abf25d0712c7ab811913001dd6ec665c8be23664428c2e173d43f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page