Metadata-Version: 2.4
Name: zero8byte
Version: 0.1.1
Summary: Official Python SDK for the 08byte Edge Data Parser & Token Compression API.
Author: 08byte
License: MIT
Project-URL: Repository, https://github.com/Sec1702/08byte
Project-URL: Homepage, https://08byte.com
Keywords: 08byte,web-scraping,llm,ai-agent,token-compression
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# zero8byte

Official Python SDK for the [08byte](https://08byte.com) Edge Data Parser & Token Compression API.

```bash
pip install zero8byte
```

Standard-library only (`urllib`) — installing this package pulls in no
other dependencies.

## Usage

```python
from zero8byte import Zero8Byte

client = Zero8Byte(api_key="zb_live_...")

# Mode-preset extraction
result = client.parse("https://jobs.example.com/software-engineer", mode="job_posting")
print(result["data"]["job_title"])

# Custom schema extraction
result = client.extract(
    "https://example.com/product/123",
    schema={
        "properties": {
            "title": {"type": "string"},
            "price": {"type": "number"},
            "in_stock": {"type": "boolean"},
        },
        "required": ["title", "price"],
    },
)

# Batch parsing (up to 50 URLs per call), polling until done
result = client.batch_parse_and_wait(
    ["https://a.example.com", "https://b.example.com"],
    mode="product",
)
print(result["status"], result["results"])

# Or fire-and-forget with a webhook instead of polling:
accepted = client.batch_parse(
    ["https://a.example.com", "https://b.example.com"],
    webhook_url="https://your-server.com/webhooks/08byte",
    webhook_secret="whsec_your_own_secret",
)
```

## Machine-to-Machine x402 Micropayments (Base USDC)

For autonomous agents and developers who want pay-per-call access without pre-funding an API key:

```python
from zero8byte import Zero8Byte

# Option A: Pre-signed X-PAYMENT header
client = Zero8Byte(x402_payment="eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC...")
res = client.parse("https://en.wikipedia.org/wiki/Artificial_intelligence")

# Option B: Dynamic auto-signing callback for 402 challenges
def sign_challenge(challenge: dict) -> str:
    # Use eth_account / web3.py to sign the EIP-712 transfer authorization
    return sign_with_evm_wallet(challenge)

agent_client = Zero8Byte(sign_payment=sign_challenge)
data = agent_client.parse("https://news.ycombinator.com")
```

## Verifying inbound batch webhooks

```python
from zero8byte import verify_webhook_signature

# raw_body MUST be the exact request bytes — not a re-serialized
# json.dumps(...) round-trip — or the signature will never match.
valid = verify_webhook_signature(
    raw_body,
    request.headers["X-08Byte-Signature"],
    os.environ["ZERO8BYTE_WEBHOOK_SECRET"],
)
```

## Error handling

Every non-2xx response raises `Zero8ByteError` (`.status`, `.code`):

```python
from zero8byte import Zero8ByteError

try:
    client.parse("http://169.254.169.254/")
except Zero8ByteError as e:
    print(e.status, e.code)  # 422 "INVALID_URL"
```

## Note on typed schemas

The Pydantic-style `Schema`/`Field` declarative API sketched in earlier
08byte docs is not implemented in this release — `extract()` takes a plain
dict matching the API's schema shape directly. Typed-model support is a
reasonable follow-up if there's demand for it.

## Requirements

Python >= 3.8.
