Skip to content

Getting started

Requirements

  • Python ≥ 3.12
  • A running SAP Commerce instance with HAC enabled

Installation

pip install hac-client-core
pip install git+https://github.com/SapCommerceTools/hac-client-core.git
git clone https://github.com/SapCommerceTools/hac-client-core.git
cd ha-client-core
pip install -e ".[dev]"

Your first script

1. Create an authentication handler

from hac_client_core import BasicAuthHandler

auth = BasicAuthHandler("admin", "nimda")

2. Create the client

from hac_client_core import HacClient

client = HacClient(
    base_url="https://localhost:9002",
    auth_handler=auth,
    ignore_ssl=True,           # skip certificate verification (dev only)
    session_persistence=True,  # cache sessions between runs
)

3. Login

client.login()

Tip

You can skip the explicit login() call — the client authenticates automatically on the first API call.

4. Execute a Groovy script

result = client.execute_groovy("return 'Hello from HAC'")
print(result.execution_result)  # "Hello from HAC"

5. Run a FlexibleSearch query

result = client.execute_flexiblesearch(
    "SELECT {pk}, {code} FROM {Product}",
    max_count=10,
)

for row in result.rows:
    print(row)

6. Import Impex data

impex = """\
INSERT_UPDATE Product; code[unique=true]; name[lang=en]
; testProduct001 ; Test Product
"""

result = client.import_impex(impex)
print("OK" if result.success else result.error)

What's next?