https://github.com/garciparedes/pascua
Python library to perform code execution in fully isolated environments
https://github.com/garciparedes/pascua
conteinerized environment environment-isolation isolate library metaprogramming package python python3
Last synced: 8 months ago
JSON representation
Python library to perform code execution in fully isolated environments
- Host: GitHub
- URL: https://github.com/garciparedes/pascua
- Owner: garciparedes
- License: mit
- Created: 2019-06-06T18:47:27.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:26:18.000Z (over 2 years ago)
- Last Synced: 2025-02-16T23:32:16.305Z (over 1 year ago)
- Topics: conteinerized, environment, environment-isolation, isolate, library, metaprogramming, package, python, python3
- Language: Python
- Homepage:
- Size: 87.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pascua
[](https://pypi.org/project/pascua)
[](https://pascua.readthedocs.io/)
[](https://travis-ci.org/garciparedes/pascua/branches)
[](https://coveralls.io/github/garciparedes/pascua)
[](https://github.com/garciparedes/pascua/blob/master/LICENSE)
[](https://github.com/garciparedes/pascua)
## Description
Python library to perform code execution in fully isolated environments.
**IMPORTANT**: This repository is in the early stage of development, so its not recommended to be used yet. Nevertheless, contributions are welcome!
## Installation
You can install the latest ``pascua`` version via ``pip``:
```bash
pip install pascua
```
## How it works?
`pascua` allow us to perform code executions in isolated environments through containerization techniques. The main idea is that `pascua` builds a `docker` image with the given parameters defined in the corresponding implementation of the `Environment` constructor.
When a call to `exec(.)` method is performed, it uses the generated `docker` image as the base in which it launches the proper interpreter or code compilation to execute the given `source_code` in combination with the variables defined in the `context` dictionary.
## Usage
### Python Environment
```python
import pascua as psc
context = {
'size': 100,
}
source_code = [
'import numpy as np',
'random_numbers = np.random.uniform(size=size)',
]
env = psc.PythonEnvironment(
version='3.7.3',
pip_dependencies=[
'numpy>=1.14.0',
]
)
result = env.exec(source_code, context)
```
### R Environment
```python
import pascua as psc
context = {
'size': 100,
}
source_code = [
'random_numbers <- runif(n = size)',
]
env = psc.REnvironment(
version='latest',
)
result = env.exec(source_code, context)
```
### C++ Environment
```python
import pascua as psc
context = {
'size': 100,
}
source_code = [
'float r;',
'vector random_numbers;',
'for (int i = 0; i < size; i++) {',
' r = static_cast (rand()) / static_cast (RAND_MAX);',
' random_numbers.push_back(r);',
'}',
]
env = psc.CCEnvironment(
version='latest',
includes=[
'vector',
'numeric',
]
)
result = env.exec(source_code, context)
```
## Development
You can install it simply typing:
```bash
python setup.py install
```
To run the tests perform:
```bash
python -m unittest discover tests
```
## License
- This project is licensed under **[MIT license](http://opensource.org/licenses/mit-license.php)**.