OpenRAM/docs/source/python_library.md

85 lines
2.0 KiB
Markdown
Raw Normal View History

### [Go Back](./index.md#table-of-contents)
# Python Library
This page explains the Python library of OpenRAM.
## Table of Contents
1. [Installation](#installation)
1. [Environment Variables](#environment-variables)
1. [Usage](#usage)
## Installation
OpenRAM is available as a Python library. There are a few ways to install it:
2023-03-16 22:10:22 +01:00
+ Install the latest _stable_ version:
```
pip3 install openram
```
+ Install the latest _dev_ version:
```
pip3 install git+https://git@github.com/VLSIDA/OpenRAM.git@dev
```
+ Install using Makefile (you need to clone the repo):
```
git clone git@github.com:VLSIDA/OpenRAM.git
cd OpenRAM
make library
```
## Environment Variables
2023-03-16 22:10:22 +01:00
OpenRAM library doesn't need any environment variables by default. However, if
you have set the environment variables explained on
[basic usage](.basic_usage.md#go-back), the library will use the OpenRAM source
code located at `OPENRAM_HOME`.
2023-03-16 22:10:22 +01:00
If you want the convenience of being able to run OpenRAM from any Python script
and have a custom OpenRAM setup, you can set these environment variables to
2023-03-16 22:10:22 +01:00
point to that OpenRAM installation directory.
If you don't want to use this feature, you can simply unset these environment
variables.
## Usage
With the OpenRAM library, you can use OpenRAM in any Python script. You can
import "openram" as follows:
```python
import openram
openram.init_openram("myconfig.py") # Config files are explained on "Basic Usage" page
# Now you can use modules from openram
from openram import tech
...
```
Note that you need to initialize OpenRAM so that the modules are imported
properly. You can also look at [sram\_compiler.py](../../sram_compiler.py) as an
example on how to use "openram."
If you want to pass custom configuration when generating an SRAM, you can use
the `sram_config` class.
```python
import openram
openram.init_openram("myconfig.py")
from openram import sram_config
c = sram_config(...)
from openram import sram
s = sram(sram_config=c,
name="custom_name")
s.save()
openram.end_openram()
```