Skip to main content

Typed, safe HeadHunter (hh.ru / hh.uz) API client with optional Django integration.

Project description

hh-api-client

Typed, safe HeadHunter (hh.ru / hh.uz) API client with optional Django integration.

Installation

pip install hh-api-client

From a Git repository (for example, the main GitHub repo):

pip install git+https://github.com/your-username/hh-api-client.git

For local development:

pip install -e .

Quick start

from hh_api_client import HHAPIClient

client = HHAPIClient(access_token="YOUR_HH_ACCESS_TOKEN")

employer = client.get_employer_info()
print(employer["id"], employer["name"])

With a token provider (recommended)

You can pass any object that implements:

  • get_valid_access_token() -> str
  • refresh_access_token() -> str

This matches your existing OrganizationHHAccount pattern.

from hh_api_client import HHAPIClient

client = HHAPIClient(organization_hh_account=my_hh_account_instance)

# Example: create vacancy
vacancy_data = {
    "name": "Python Developer",
    "description": "<p>We are looking for a Python developer...</p>",
    "area": {"id": "2759"},  # e.g. Tashkent
    "employment": {"id": "full"},
    "schedule": {"id": "fullDay"},
}

response = client.create_vacancy(vacancy_data)
print(response["id"])

Django integration example

Assuming you have a model like OrganizationHHAccount with methods:

  • get_valid_access_token()
  • refresh_access_token()

and you store it per organization:

from hh_api_client import HHAPIClient
from organization_app.models import OrganizationHHAccount


def get_hh_client_for_organization(organization) -> HHAPIClient:
    hh_account = OrganizationHHAccount.objects.get(organization=organization, archived=False)
    return HHAPIClient(organization_hh_account=hh_account)

Configuring base URL (hh.uz vs hh.ru)

By default this client uses the Uzbekistan API base URL https://api.hh.uz because that is a common production setup.

If you need to change it (for example to https://api.hh.ru), use HHAPIClientConfig:

from django.conf import settings
from hh_api_client import HHAPIClient, HHAPIClientConfig
from organization_app.models import OrganizationHHAccount


def get_hh_client_for_organization(organization) -> HHAPIClient:
    hh_account = OrganizationHHAccount.objects.get(organization=organization, archived=False)
    config = HHAPIClientConfig(base_url=getattr(settings, "HH_API_BASE_URL", "https://api.hh.uz"))
    return HHAPIClient(organization_hh_account=hh_account, config=config)

You can wire it to your existing settings:

# settings/base.py
HH_CLIENT_ID = env.str("HH_CLIENT_ID", default="")
HH_CLIENT_SECRET = env.str("HH_CLIENT_SECRET", default="")
HH_REDIRECT_URI = env.str("HH_REDIRECT_URI", default="")
HH_API_BASE_URL = "https://api.hh.uz"  # or api.hh.ru
HH_OAUTH_BASE_URL = "https://hh.uz"

Then your existing usage in signal handlers and DRF views can stay almost the same, just update the import:

from hh_api_client import HHAPIClient

Safety and error handling

  • No secrets (tokens) are ever logged.
  • Network errors raise requests.RequestException.
  • API-level errors raise hh_api_client.HHAPIError with a sanitized message.
  • Automatic token refresh is attempted once on 401 responses when a token provider is used.

Endpoints covered

High-level helpers currently implemented:

  • get_user_info()
  • get_employer_info()
  • get_managers()
  • get_default_manager_id()
  • get_employer_services()
  • get_publication_status()
  • test_connection()

Vacancies:

  • create_vacancy()
  • update_vacancy()
  • archive_vacancy()
  • publish_vacancy()
  • extend_vacancy()
  • get_vacancy()
  • get_vacancies()

Resumes:

  • search_resumes()
  • get_resume()

Negotiations:

  • get_negotiations()
  • get_vacancy_candidates()

Releasing (for maintainers)

This project is configured to publish using GitHub Actions and PyPI's OpenID Connect (OIDC) publisher.

  • A GitHub Actions workflow lives at .github/workflows/workflow.yml.
  • When you push a tag like v0.1.0 to the hh-api-client repository on GitHub, the workflow:
    • Builds the package with python -m build.
    • Publishes the distributions to TestPyPI (environment testpypi).
    • Then publishes the same build to PyPI (environment pypi).

To cut a new release:

  1. Bump the version in pyproject.toml.

  2. Commit and push to main.

  3. Create and push a tag, e.g.:

    git tag v0.1.2
    git push origin v0.1.2
    
  4. Wait for the GitHub Actions workflow to complete; the new version will appear on both TestPyPI and PyPI (assuming both publishers are configured).

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

hh_api_client-0.1.4.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hh_api_client-0.1.4-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file hh_api_client-0.1.4.tar.gz.

File metadata

  • Download URL: hh_api_client-0.1.4.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hh_api_client-0.1.4.tar.gz
Algorithm Hash digest
SHA256 245dd670e6ade65e12bcda7fbdd09e6d894ecc9be4b32ab78e43646e84163e06
MD5 3741dec094abaae224cbde3cc23e3d80
BLAKE2b-256 288c04a3bc3fff45d99cc9f90d57f22078b217cd1111c56ca213c1e8c0286dc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hh_api_client-0.1.4.tar.gz:

Publisher: workflow.yml on Firdavs0809/hh-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hh_api_client-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: hh_api_client-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hh_api_client-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3f53fc66b0355fc919fe4553f89f30c3e0dc92bc721dc83c05109fdb56038eb9
MD5 94df275e895377bd5a4b671fee869986
BLAKE2b-256 4735bb2dc6b12ff8c8f04f2d5081a586b08c3396f717d42451dcd6c9eb366663

See more details on using hashes here.

Provenance

The following attestation bundles were made for hh_api_client-0.1.4-py3-none-any.whl:

Publisher: workflow.yml on Firdavs0809/hh-api-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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