Metadata-Version: 2.4
Name: hackerrank
Version: 2026.11.24
Summary: Interact with the HackerRank for Work API.
Author-email: Adam Dangoor <adamdangoor@gmail.com>
License-Expression: MIT
Project-URL: Documentation, https://adamtheturtle.github.io/hackerrank/
Project-URL: Source, https://github.com/adamtheturtle/hackerrank
Keywords: client,hackerrank,interview
Classifier: Development Status :: 1 - Planning
Classifier: Environment :: Web Environment
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.13
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: beartype>=0.23.0
Requires-Dist: httpx>=0.28.0
Requires-Dist: httpx2>=2.12.0
Requires-Dist: pydantic>=2.14.4
Requires-Dist: pyyaml>=6
Requires-Dist: tenacity>=9.1.4
Dynamic: license-file

|Build Status| |PyPI|

hackerrank
==========

Python library for the `HackerRank for Work API`_.

.. _HackerRank for Work API: https://www.hackerrank.com/work/apidocs

Installation
------------

.. code-block:: shell

   pip install hackerrank

This is tested on Python |minimum-python-version|\+.

Getting Started
---------------

Generate an API token from the `HackerRank for Work tokens page`_ and pass it as ``api_key``:

.. code-block:: python

   """Example usage."""

   import sys

   from hackerrank.client import HackerRank

   client = HackerRank(api_key="your-api-key")
   for test in client.tests.list().data:
       _ = sys.stdout.write(test.name)
   interview = client.interviews.create(title="My Interview")
   _ = sys.stdout.write(interview.url)

.. _HackerRank for Work tokens page: https://www.hackerrank.com/work/settings/token

Updating private notes
----------------------

Use ``client.questions.update_internal_notes(question_id=..., internal_notes=...)`` to change private interviewer notes.
The same operation is available on ``AsyncHackerRank``.
Each call reads the required question fields before writing the requested notes, including identical or empty notes.
The operation returns the question supplied by the update response, or ``None`` for an empty response.
It raises ``ValueError`` if fields required by the update request are absent.

HTTPX2 transports
-----------------

HTTPX remains the default client family.
To opt in to HTTPX2, construct the HTTPX2 transport explicitly and pass it to the client.
The standard ``hackerrank`` installation includes both client families.

.. code-block:: python

   """Configure HackerRank to use HTTPX2."""

   import httpx2

   from hackerrank.client import HackerRank
   from hackerrank.transports import HTTPX2Transport

   transport = HTTPX2Transport(timeout=httpx2.Timeout(timeout=10))
   with HackerRank(api_key="your-api-key", transport=transport) as client:
       tests = client.tests.list()

Use ``AsyncHTTPX2Transport`` with ``AsyncHackerRank`` for asynchronous calls.
The ``timeout`` argument accepts an HTTPX2 timeout object or a number of seconds.
Existing HTTPX configurations continue to work.
Pass HTTPX2 timeout objects to HTTPX2 transports.
Migrating to HTTPX2 only requires selecting the new transport.
HackerRank client methods and returned models are unchanged.

Question types and AI prompts
-----------------------------

Use ``hackerrank.types.QuestionType`` for known API question types.
The clients continue to accept strings, and ``Question.type`` preserves unknown response values so newer server types remain readable.
``QuestionType.supports_custom_system_prompt`` and ``Question.supports_custom_system_prompt`` report known prompt support.

Typed and generic question writes reject prompts longer than 15,000 characters and prompts supplied for known unsupported types before sending a request.
Generic partial updates can omit the type.
The server validates whether the field applies.
Invalid requests retain the supplied prompt.

Native project configuration
----------------------------

Pass the version and nested settings of a native ``hackerrank.yml`` to ``ProjectConfiguration``.
Call ``to_yaml()`` to render the configuration as UTF-8 YAML bytes.

.. code-block:: python

   """Render a HackerRank project configuration."""

   from hackerrank.project_configuration import ProjectConfiguration

   configuration = ProjectConfiguration(
       version=1.0,
       configuration={
           "has_webserver": False,
           "readonly_paths": ["tests"],
           "scoring": {"command": "grade", "files": ["report.xml"]},
           "ide_config": {
               "default_open_files": ["solution.py"],
               "project_menu": {"run": "python solution.py"},
           },
       },
   ).to_yaml()
   assert configuration.startswith(b"version: 1.0\n")

Pass the configuration bytes and an existing project ZIP to ``hackerrank.project_configuration.configure_project_archive``.
Pass the resulting ZIP bytes to ``client.questions.upload_project_zip``.

Full Documentation
------------------

See the `full documentation <https://adamtheturtle.github.io/hackerrank/>`__.

.. |Build Status| image:: https://github.com/adamtheturtle/hackerrank/actions/workflows/ci.yml/badge.svg?branch=main
   :target: https://github.com/adamtheturtle/hackerrank/actions
.. |PyPI| image:: https://badge.fury.io/py/hackerrank.svg
   :target: https://badge.fury.io/py/hackerrank
.. |minimum-python-version| replace:: 3.13

Interviews V2 and audit logs
----------------------------

``client.interviews.get_artifacts`` returns typed artifact metadata or an ``InterviewArtifactsPending`` result with the server's retry delay.
Signed download URLs expire.
Request fresh metadata when needed.
``get_notes`` reads permitted interviewer notes and ``update_note`` replaces the current user's note, preserving empty content.

Use ``client.audit_logs.list_cursor`` for large audit collections.
Pass the returned ``next_cursor`` to continue.
Subsequent requests send only that opaque token.
Both audit methods support the documented filters, including ``user``.
The existing ``user_id`` argument sends the documented ``user`` query key.
Offset pages expose the server's window limit and exhaustion flag.
All operations are also available on ``AsyncHackerRank``.

Complete API operation catalogue
--------------------------------

``hackerrank.api.api_operations()`` lists every documented v3 and SCIM operation.
``client.api.call`` accepts the operation name, path parameters, query fields and complete JSON body, retaining the response status, headers and data.
SCIM calls require their own ``scim_api_key`` and use the provisioning host.
The same catalogue and execution interface are available asynchronously.


Offline project archives
------------------------

Use ``hackerrank.projects.build_project_archive`` to build a project ZIP from explicitly chosen local files.
Pass the resulting ZIP bytes to ``client.questions.upload_project_zip``.
