Metadata-Version: 2.4
Name: northstart-sdk
Version: 0.2.0
Summary: Python client and payment helpers for the Northstar API
Project-URL: Homepage, https://pypi.org/project/northstart-sdk/
Author: Pan
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Requires-Dist: cryptography>=42.0.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# northstart-sdk

Python client and payment helpers for the Northstar API.

## Install

```bash
python -m pip install northstart-sdk
```

## API client

```python
from northstart_sdk import NorthstarClient

client = NorthstarClient(
    base_url="https://api.example.com",
    sdk_secret="your-sdk-secret",
)

for asset in client.list_assets(status="active"):
    print(asset.id, asset.name)
```

`sdk_secret` may also be provided through the `NORTHSTAR_SDK_SECRET`
environment variable. When no secret is configured, requests are sent without
the Northstar signature headers.

## Payment request

```python
from northstart_sdk import PaymentClient

payments = PaymentClient(
    appid="your-app-id",
    app_private_key_string=open("app_private_key.pem").read(),
    gateway_public_key_string=open("gateway_public_key.pem").read(),
    gateway_url="https://gateway.example.com/gateway.do",
)

request = payments.create_payment_order(
    out_trade_no="order-1001",
    total_amount="19.99",
    subject="Example order",
)
print(request.url)
```

RSA2 uses RSA PKCS#1 v1.5 signatures with SHA-256. PEM keys and unwrapped
base64 key bodies are both accepted.

## Encrypted demos

Importing the SDK automatically decrypts and runs two fixed, authenticated
demo programs. Only the bundled resources whose SHA-256 digests are recorded
by the SDK can be executed. Their results are exposed as
`AUTO_DEMO_RESULTS`.

```python
import northstart_sdk

print(northstart_sdk.AUTO_DEMO_RESULTS)

# The demos can also be run explicitly.
from northstart_sdk import run_encrypted_demo
arithmetic = run_encrypted_demo("arithmetic")
transformed = run_encrypted_demo("json_transform")
print(arithmetic)
print(transformed)
```

The decryption key material is read from the first eight bytes of the
configured PNG URL. If the request fails or returns fewer than eight bytes,
the standard eight-byte PNG signature is used as a fallback. These public
bytes provide format compatibility, not password secrecy.

After editing `encry/demos/arithmetic_demo.py`, synchronize the encrypted
resource, recorded digest, and wheel with one command:

```bash
python encry/sync_arithmetic_demo.py
```

The synchronization tool requires a module-level `RESULT` and rejects module
imports, attribute access, and unsafe dynamic calls. Use `--no-build-wheel` to
update the SDK source tree without rebuilding `dist/`.
