Python package for Litex core
Project description
Pylitex
This is a Python api library for Litex core, which aims to help Python users to interact with Litex core.
Installation
💡 Install Litex core before using
pylitex, visit our website and read the Installation of Litex core.
After installing Litex core on your machine, install pylitex in the same way as installing other Python packages:
# remember to install Litex core before install pylitex
# change your Python env to which your are using
# then run following commands
pip install pylitex
pylitex is under rapid development, so the version is not stable. Update pylitex using the following command:
pip install -U pylitex
Usage
Import pylitex as you installed.
import pylitex
Run full code
1 + 1 = 2 and 2 + 2 = 4 are examples of Litex code. You can write your own Litex code.
# run full code
result = pylitex.run("1 + 1 = 2")
# run full codes with multi-process
results = pylitex.run_batch(["1 + 1 = 2", "2 + 2 = 4"], 2)
Example:
import pylitex
a = 1
b = 1
pylitex.run(str(a) + " = " + str(b))
Run full code via internet
1 + 1 = 2 and 2 + 2 = 4 are examples of Litex code. You can write your own Litex code.
# run full code
result = pylitex.run_online("1 + 1 = 2")
# run full codes with multi-process
results = pylitex.run_batch_online(["1 + 1 = 2", "2 + 2 = 4"], 2)
Example:
import pylitex
a = 1
b = 1
pylitex.run_online(str(a) + " = " + str(b))
Run continuous codes
# run continuous codes in one litex env
litex_runner = pylitex.Runner()
result1 = litex_runner.run("1 + 1 = 2")
result2 = litex_runner.run("2 + 2 = 4")
litex_runner.close()
# run continuous code in litex multi-process pool
litex_pool = pylitex.RunnerPool()
litex_pool.inject_code({id: "id1", code: "1 + 1 = 2"})
litex_pool.inject_code({id: "id2", code: "2 + 2 = 4"})
litex_pool.inject_code({id: "id1", code: "1 + 1 = 2"})
litex_pool.inject_code({id: "id1", code: "2 + 2 = 4"})
litex_pool.inject_code({id: "id2", code: "2 + 2 = 4"})
results = litex_pool.get_results()
litex_pool.close()
Example:
import pylitex
runner = pylitex.Runner()
runner.run("let a R: a = 1")
runner.run("let b R: b = 2")
runner.run("b = 2 * a")
runner.close()
Compare
| function | environment | required local litex installation | multithread |
|---|---|---|---|
pylitex.run() |
New environment for each code | ✅ | ❌ |
pylitex.run_batch() |
New environment for each code | ✅ | ✅ |
pylitex.run_online() |
New environment for each code | ❌ | ❌ |
pylitex.run_batch_online() |
New environment for each code | ❌ | ✅ |
pylitex.Runner().run() |
Continuous environment for all code | ✅ | ❌ |
pylitex.RunnerPool().inject_code() |
Distribute environment for each code by id |
✅ | ✅ |
Return type
For pylitex.run(), pulitex.run_online() and pylitex.Runner().run(), the return type is a python dict like (Call it pylitexResult):
{"success": boolean, "payload": str, "message": str}
For pylitex.run_batch() and pylitex.run_batch_online() the return type is a python list[pylitexResult] like:
[
{"success": boolean, "payload": str, "message": str},
{"success": boolean, "payload": str, "message": str},
...
]
For pylitex.RunnerPool().get_results(), the return type is a python dict[list[pylitexResult]] like:
{
"id1": [
{"success": boolean, "payload": str, "message": str},
{"success": boolean, "payload": str, "message": str},
{"success": boolean, "payload": str, "message": str},
...
],
"id2": [
{"success": boolean, "payload": str, "message": str},
{"success": boolean, "payload": str, "message": str},
...
],
...
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylitex-0.1.17.tar.gz.
File metadata
- Download URL: pylitex-0.1.17.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
375a8df26e7e50d3b85a3c49d19093bb0df5a6ffb6032607e8faaa835100201e
|
|
| MD5 |
4f6d391acd6c9917b6f3cd0408fe78e8
|
|
| BLAKE2b-256 |
e79c94946ee9422ca3fc581e8bc58a2d526da574708ce65f00eebce730806b93
|
File details
Details for the file pylitex-0.1.17-py3-none-any.whl.
File metadata
- Download URL: pylitex-0.1.17-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e510a42b169230a3c93f09312043cdbe057338f8943c2600cc039716ab245ce8
|
|
| MD5 |
b3484ffd035b63ba05055f6cd5f38ff6
|
|
| BLAKE2b-256 |
f59eb446d06e547f4379733373aa83476b56e53b09a236868329204e5101bfeb
|