Metadata-Version: 2.4
Name: liberty-tools
Version: 0.1.0
Summary: Python library for parsing, representing, and manipulating Liberty (.lib) files
License-File: LICENSE
Author: Daniel Schmeer
Author-email: dschmeer@cryptoquantique.com
Requires-Python: >=3.12,<4.0.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
Description-Content-Type: text/markdown

# liberty-tools

`liberty-tools` is a clean, robust, and lightweight Python library for parsing, representing, and manipulating Liberty (`.lib`) files, commonly used in Electronic Design Automation (EDA) workflows for standard cell and memory library characterization.

## Features

- **Lexer & Parser:** Full lexical analysis and parsing of Liberty syntax, including arrays, complex groups, bus structures, bundles, lookup tables (LUTs), operating conditions, and k-factors.
- **Pydantic Validation:** Fully-typed data models validated via `pydantic` v2, allowing for robust IDE autocompletion and static type analysis.
- **Serialization (Writer):** Write model hierarchies back to fully-compliant Liberty syntax format with controllable formatting and indentation.
- **PVT & Corner Management:** Helper functions to generate, normalize, and manage operating conditions, temperatures, voltages, and process skews (e.g., typical/corner PVTs).

## Installation

You can install `liberty-tools` from PyPI using pip:

```bash
pip install liberty-tools
```

Or add it to your Poetry project:

```bash
poetry add liberty-tools
```

## Quick Start

### Parsing a Liberty File

```python
from liberty_tools import LibertyReader

liberty_text = """
library (my_typical_library) {
  comment : "Sample Library";
  delay_model : table_lookup;
  voltage_unit : "1V";

  cell (AND2_X1) {
    area : 1.064;
    pin (A) {
      direction : input;
      capacitance : 0.005;
    }
    pin (Y) {
      direction : output;
      function : "(A)";
    }
  }
}
"""

# Parse the text into a Library model
reader = LibertyReader(liberty_text)
library = reader.parse()

print(f"Parsed library: {library.name}")
print(f"Delay Model: {library.delay_model}")
print(f"Cells in library: {[cell.name for cell in library.cells]}")
```

### Serializing back to Liberty Syntax

```python
from liberty_tools import LibertyWriter

writer = LibertyWriter(indent_size=2)
output_text = writer.write(library)
print(output_text)
```

### PVT Corner Generation

```python
from liberty_tools import create_corners

process_info = {
    "process_names": ["tt", "ss", "ff"],
    "io_voltage": [1.8],
    "core_voltage": [0.9],
    "temperature": [25, 125]
}

corners = create_corners(process_info)
for corner in corners:
    print(f"Corner: {corner.core_name} (Core: {corner.v_core}V, IO: {corner.v_io}V, Temp: {corner.temp}C)")
```

## Development and Testing

### Setup

Clone the repository and install development dependencies using Poetry:

```bash
git clone https://github.com/your-username/liberty-tools.git
cd liberty-tools
poetry install
```

### Running Tests

Run the full test suite with coverage:

```bash
poetry run pytest
```

## License

This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.

