Metadata-Version: 2.4
Name: svlang-sdk
Version: 0.7.0
Summary: Zero-build-dependency Python bindings for the svlang EDA Compiler SDK (ctypes + Apache Arrow PyCapsule Interface)
Author-email: Mayur Kubavat <mkubavat01@gmail.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/mayurkubavat/svlang
Project-URL: Repository, https://github.com/mayurkubavat/svlang
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: arrow
Requires-Dist: pyarrow>=14.0; extra == "arrow"

# `svlang-sdk` — Zero-Build-Dependency Python SDK

Pure-Python (`ctypes`) bindings over the frozen svlang C11 ABI v1.1 (`libsvlang_sdk_c`), with zero required third-party dependencies and native **Apache Arrow PyCapsule Interface** zero-copy export (`__arrow_c_schema__` / `__arrow_c_array__`).

## Library Discovery

`svlang_sdk` locates `libsvlang_sdk_c.{dylib,so,dll}` automatically in priority order:

1. `SVLANG_SDK_LIB` — exact shared library file path
2. `SVLANG_SDK_LIB_DIR` — directory containing the shared library
3. Sibling repository build directories (`sdk/build/release/abi/c/`, `sdk/build/dev/abi/c/`)
4. Standard OS library search (`ctypes.util.find_library("svlang_sdk_c")` / dynamic linker paths)

## Quick Start

```python
import pyarrow as pa
from svlang_sdk import AtomicChange, Durability, Graph, Host, Registry, abi_version

print("C ABI:", abi_version())  # (1, 1)

with Host() as host:
    host.set_file(
        "rtl/top.sv",
        "module top(input logic [7:0] a, output logic [7:0] y); assign y = ~a; endmodule\n",
        Durability.LOW,
    )
    host.set_file(
        "pwr/top.upf",
        "upf_version 3.1\ncreate_power_domain PD_TOP -include_scope\n",
        Durability.HIGH,
    )

    with host.take_snapshot() as snap, snap.build_graph("top") as graph:
        # Zero-copy Apache Arrow PyCapsule export (no pyarrow.cffi boilerplate).
        arr = pa.array(graph.entities_arrow())
        batch = pa.RecordBatch.from_struct_array(arr)
        print(batch.num_rows, batch.schema.names)

        # Immutable .svdb snapshot persistence (ABI v1.1).
        graph.save_svdb("top.svdb")
        summary = Graph.inspect_svdb("top.svdb")
        with Graph.load_svdb("top.svdb") as loaded:
            assert loaded.entity_count == summary["entity_count"]
```

Without `pyarrow` installed, `ArrowEntityTable` still supports pure-Python inspection:

```python
with graph.entities_arrow() as table:
    print(table.row_count, table.column_names)
    rows = table.to_pylist()
```

## Public API

- **Lifecycle & Errors:** `abi_version()`, `inspect_svdb(path)`, `Durability`, `StatusCode`, `SdkError` (`.code`, `.message`)
- **`Host`:** `revision`, `set_file(path, content, durability=Durability.LOW)`, `remove_file(path)`, `take_snapshot()`
- **`Snapshot`:** `revision`, `is_cancelled`, `build_graph(top_module=None)`, `lint_file(path)`
- **`Graph`:** `entity_count`, `find_entity(path)`, `export_entities(...)`, `fanin_cone(...)`, `explain_overlay(...)`, `apply_overlay_str(...)`, `power_crossings()`, `entities_arrow()`, `save_svdb(path)`, `Graph.load_svdb(path)`, `Graph.inspect_svdb(path)`
- **`ArrowEntityTable`:** `__arrow_c_schema__()`, `__arrow_c_array__(requested_schema=None)`, `row_count`, `column_count`, `column_names`, `column_formats`, `to_pylist()`, `close()`
- **`AtomicChange`:** `add_edit(...)`, `preview(snapshot, ...)`, `apply_to_host(host, ...)`
- **`Registry`:** `register_builtins()`, `list_plugins()`, `run_passes(graph)`

## Running Tests

```bash
PYTHONPATH=sdk/bindings/python python3 -m unittest discover -s sdk/bindings/python/tests -v
```
