PandoraBox


NamePandoraBox JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/pydaxing/PandoraBox
SummaryPandora Box Is All You Need. You Can Create Python Environment, Execute Python, Close Python Environment Freely and Easily.
upload_time2024-10-29 07:35:17
maintainerNone
docs_urlNone
authorpydaxing
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pandora Box: A Revolutionary Open-Source Python Environment
![](./logo.jpg)

[English](./README.MD) | [中文](./README_ZH.MD)

In the era of Large Language Models (LLMs), Pandora Box emerges as a pioneering open-source Python package, specifically designed to empower developers and innovators in the creation of LLM-based applications and agents. This versatile tool is engineered to provide a robust and secure Python environment, facilitating the seamless integration and execution of LLM-driven projects. Completely free and easily deployable via pip install, Pandora Box is set to revolutionize the way developers approach LLM-based development.

Key Advantages of Pandora Box:

- **Fully Open-Source and Free**: Embrace the open development ethos with Pandora Box, offering complete access to its source code. This ensures a collaborative and evolving platform for developers working on LLM applications and agents, without any financial barriers.

- **Seamless Local Deployment**: Get started instantly with a simple pip install command. Pandora Box's ease of installation on local machines allows developers to quickly set up and dive into LLM-based project development.

- **Versatile Application**: Whether you're developing LLM-based agents that run Python scripts or deploying sophisticated AI services via HTTP, Pandora Box provides the flexibility and tools needed to bring your vision to life.

- **Efficient Environment Management**: Create, execute, and close Python environments with unparalleled ease. Pandora Box streamlines the development process, enabling developers to focus on innovation rather than environment setup and management.

- **Ideal for LLM-Based Agents**: Pandora Box is specifically tailored to meet the needs of LLM-based application development. It offers a secure environment for running python code, ensuring that your LLM agents can operate efficiently.

Pandora Box is not just a Python package; it's a gateway to the future of LLM-based development. By offering a secure, easy-to-use, and completely open-source solution, it enables developers to explore the full potential of their LLM applications and agents. Whether you're creating a coding copilot, an AI data analyst, or any other LLM-powered tool, Pandora Box provides the foundation you need to innovate and excel in the LLM era.

## Installation
To ensure environment isolation and security, it is best to use `conda` to create a separate virtual environment.

```commandline
# python >= 3.11
conda create -n pandora-box python=3.11
conda activate pandora-box
pip install PandoraBox
```

## How to use
Pandora Box can be utilized in two distinct manners: either through Python scripts or via HTTP services, thereby catering to a variety of usage scenarios.

### HTTP Server
The HTTP Server is primarily used with the `pbox` command, which includes the creation and querying of API KEYS, and the starting of the HTTP Server. You can view detailed information by using "pbox -h".

```commandline
$ pbox -h
```
```commandline
usage: pbox [-h] {s,a,l,d} ...

positional arguments:
  {s,a,l,d}
    s         Start Pandora Box Server
    a         Add new API KEY
    l         List all API KEYS
    d         Del API KEY

options:
  -h, --help  show this help message and exit
```

Before starting the HTTP Server, you need to first create an API KEY using the following command, which will be used for authentication when accessing the HTTP Server you create next.

```commandline
$ pbox a
```
```text
pb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

You can create multiple API KEYS through the above method.

Then, you can view all the API KEYS you have created by following command:
```commandline
$ pbox l
```
```text
API-KEY-1
...
API-KEY-n
```

And, you can delete a api_key by:
```commandline
$ pbox d <your-api-key>
```

Now, you can start the HTTP Server using the this command:
```commandline
$ pbox s
```

By default, the service starts at the address `0.0.0.0` and port `9501`. You can specify the startup address and port by passing the `server` and `port` parameters when using the `pbox s` command.

```commandline
$ pbox s --server x.x.x.x --port xxxx
```

```commandline
$ pbox s -h
```
```commandline
usage: pbox s [-h] [--server SERVER] [--port PORT]

options:
  -h, --help       show this help message and exit
  --server SERVER  Server address
  --port PORT      Port
```

Congratulation🎉, you have launched the HTTP Server. You can view the API documentation at http://127.0.0.1:9501/docs.

#### Health Check
You can use `curl` to check the health status of the http server:
```commandline
$ curl http://127.0.0.1:9501/health
```
```text
success
```

#### Create Python SandBox
You can create a Python sandbox as follows:
```commandline
$ curl http://127.0.0.1:9501/create \
-H "API-KEY: your-api-key"
```
```json
{
    "kernel_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

You will receive a kernel_id, which is the unique identifier for the Python box. If a kernel_id is returned after creation, it indicates that the creation was successful.

#### List Python SandBox
The current Python environments that have been created can be queried in the following way.
```commandline
$ curl http://127.0.0.1:9501/sandbox \
-H "API-KEY: your-api-key"
```
```json
{
  "kernel_ids":[
    "kernel_id_1", 
    "kernel_id_2", 
    "...", 
    "kernel_id_n"]
}
```



#### Execute Python Code
You can now execute Python code in this Python Box:
```commandline
$ curl http://127.0.0.1:9501/execute \
-H "API-KEY: your-api-key" \
-H "Content-Type: application/json; charset=utf-8" \
-H "KERNEL-ID: your-kernel-id" \
-d '{
    "code": "print(\"Hello, Pandora Box!\")"
}'
```
```json
{
  "results": [],
  "logs": {
    "stdout": ["Hello, Pandora Box!"],
    "stderr": []
  },
  "error": null
}
```

`results` has base64 encoded image, if you use matplotlib to plot a picture.

`logs` printed to stdout and stderr during execution. Examples of logs are print statements, warnings, subprocess output, etc. It contains two fields:
- `stdout`: List of strings, each string is a line printed to stdout.
- `stderr`: List of strings, each string is a line printed to stderr.

`error` message, if there was an error during execution of the cell. It contains three fields:

- `name`: Name of the error, e.g. NameError, ValueError, etc.
- `value`: Value of the error, e.g. name 'non_existent_variable' is not defined, etc.
- `traceback`: Traceback of the error.

#### Close Python Sandbox
When you don't need to use the Python environment, you can close it in time to reduce resource waste.

```commandline
$ curl http://127.0.0.1:9501/close \
-H "API-KEY: your-api-key" \
-H "KERNEL-ID: your-kernel-id"
```
```json
{
  "message": "Sandbox Closed."
}
```

Each kernel, if not manually closed, will automatically shut down after 6 hours. This means that the maximum duration for each kernel is 6 hours. This is to avoid wasting resources. The current version does not support duration settings yet.

### Python Script
You can directly import the pbox package in your Python script for use. If you don't need any Python environment management or API KEY authentication features, you can directly use CodeSandBox to create a Python environment and execute the code.
```python
from pbox import CodeSandBox

code_sandbox = CodeSandBox()
result = code_sandbox.execute_code("print('Hello, PandaroBox!')")

print(str(result))
print(result.logs.stdout)
```
```text
Result(results=[], logs=Logs(stdout=['Hello, PandaroBox!'], stderr=[]), error=None)
['Hello, PandaroBox!']
```

The returned result is a `Result` class, which you can view the specific content by using `str()`. The `results` contained within the `Result` is a list. `Logs` is also a class similar to `Result`, containing two lists: `stdout` and `stderr`. The `error` is `null` when the code executes normally, and it is an `Error` class when there is a code error, containing three attributes: `name`, `value`, and `traceback`. The values in `Result`, `Logs`, and `Error` can be accessed using the `.` operator, such as `result.logs.stdout`.

`CodeSandBox` has the ability to remember the context of Python code until it is closed.
```python
from pbox import CodeSandBox

code_sandbox = CodeSandBox()
code_sandbox.execute_code("x = 'Hello, PandoraBox!'")
result = code_sandbox.execute_code("print(x)")

print(str(result))
```
```text
Result(results=[], logs=Logs(stdout=['Hello, PandoraBox!'], stderr=[]), error=None)
```
If you no longer need it, you can directly close it.

```python
code_sandbox.close()
```

If you require an API KEY authentication mechanism and the mechanism for kernels to automatically close after 6 hours, you can use `CodeSandBoxManager` to create and close sandboxes as well as execute code.
```python
from pbox import CodeSandBoxManager

csb_manager = CodeSandBoxManager()

# creqte sandbox
kernel_id = csb_manager.create_sandbox("your-api-key")

# list sandbox
csb_manager.get_sandbox("your-api-key")

# execute code
result = csb_manager.execute_code (
    "your-api-key",
    "your-kernel-id",
    "print('Hello, Pandaro Box!')"
)

# close sandbox, If you forget, it will automatically close after 6 hours.
csb_manager.close_sandbox(
    "your-api-key",
    "your-kernel-id"
)
```

## Contributing
Feel free to contribute to this project. You can open an issue or submit a pull request.

## Contact info
You can contact at pydaxing@gmail.com

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pydaxing/PandoraBox",
    "name": "PandoraBox",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "pydaxing",
    "author_email": "pydaxing@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/5f/2bdc5abcbf24a6a489889e3531cbdcdfe2b3bd0ef8e3a352e6f513614620/pandorabox-1.2.0.tar.gz",
    "platform": null,
    "description": "# Pandora Box: A Revolutionary Open-Source Python Environment\n![](./logo.jpg)\n\n[English](./README.MD) | [\u4e2d\u6587](./README_ZH.MD)\n\nIn the era of Large Language Models (LLMs), Pandora Box emerges as a pioneering open-source Python package, specifically designed to empower developers and innovators in the creation of LLM-based applications and agents. This versatile tool is engineered to provide a robust and secure Python environment, facilitating the seamless integration and execution of LLM-driven projects. Completely free and easily deployable via pip install, Pandora Box is set to revolutionize the way developers approach LLM-based development.\n\nKey Advantages of Pandora Box:\n\n- **Fully Open-Source and Free**: Embrace the open development ethos with Pandora Box, offering complete access to its source code. This ensures a collaborative and evolving platform for developers working on LLM applications and agents, without any financial barriers.\n\n- **Seamless Local Deployment**: Get started instantly with a simple pip install command. Pandora Box's ease of installation on local machines allows developers to quickly set up and dive into LLM-based project development.\n\n- **Versatile Application**: Whether you're developing LLM-based agents that run Python scripts or deploying sophisticated AI services via HTTP, Pandora Box provides the flexibility and tools needed to bring your vision to life.\n\n- **Efficient Environment Management**: Create, execute, and close Python environments with unparalleled ease. Pandora Box streamlines the development process, enabling developers to focus on innovation rather than environment setup and management.\n\n- **Ideal for LLM-Based Agents**: Pandora Box is specifically tailored to meet the needs of LLM-based application development. It offers a secure environment for running python code, ensuring that your LLM agents can operate efficiently.\n\nPandora Box is not just a Python package; it's a gateway to the future of LLM-based development. By offering a secure, easy-to-use, and completely open-source solution, it enables developers to explore the full potential of their LLM applications and agents. Whether you're creating a coding copilot, an AI data analyst, or any other LLM-powered tool, Pandora Box provides the foundation you need to innovate and excel in the LLM era.\n\n## Installation\nTo ensure environment isolation and security, it is best to use `conda` to create a separate virtual environment.\n\n```commandline\n# python >= 3.11\nconda create -n pandora-box python=3.11\nconda activate pandora-box\npip install PandoraBox\n```\n\n## How to use\nPandora Box can be utilized in two distinct manners: either through Python scripts or via HTTP services, thereby catering to a variety of usage scenarios.\n\n### HTTP Server\nThe HTTP Server is primarily used with the `pbox` command, which includes the creation and querying of API KEYS, and the starting of the HTTP Server. You can view detailed information by using \"pbox -h\".\n\n```commandline\n$ pbox -h\n```\n```commandline\nusage: pbox [-h] {s,a,l,d} ...\n\npositional arguments:\n  {s,a,l,d}\n    s         Start Pandora Box Server\n    a         Add new API KEY\n    l         List all API KEYS\n    d         Del API KEY\n\noptions:\n  -h, --help  show this help message and exit\n```\n\nBefore starting the HTTP Server, you need to first create an API KEY using the following command, which will be used for authentication when accessing the HTTP Server you create next.\n\n```commandline\n$ pbox a\n```\n```text\npb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\nYou can create multiple API KEYS through the above method.\n\nThen, you can view all the API KEYS you have created by following command:\n```commandline\n$ pbox l\n```\n```text\nAPI-KEY-1\n...\nAPI-KEY-n\n```\n\nAnd, you can delete a api_key by:\n```commandline\n$ pbox d <your-api-key>\n```\n\nNow, you can start the HTTP Server using the this command:\n```commandline\n$ pbox s\n```\n\nBy default, the service starts at the address `0.0.0.0` and port `9501`. You can specify the startup address and port by passing the `server` and `port` parameters when using the `pbox s` command.\n\n```commandline\n$ pbox s --server x.x.x.x --port xxxx\n```\n\n```commandline\n$ pbox s -h\n```\n```commandline\nusage: pbox s [-h] [--server SERVER] [--port PORT]\n\noptions:\n  -h, --help       show this help message and exit\n  --server SERVER  Server address\n  --port PORT      Port\n```\n\nCongratulation\ud83c\udf89, you have launched the HTTP Server. You can view the API documentation at http://127.0.0.1:9501/docs.\n\n#### Health Check\nYou can use `curl` to check the health status of the http server:\n```commandline\n$ curl http://127.0.0.1:9501/health\n```\n```text\nsuccess\n```\n\n#### Create Python SandBox\nYou can create a Python sandbox as follows:\n```commandline\n$ curl http://127.0.0.1:9501/create \\\n-H \"API-KEY: your-api-key\"\n```\n```json\n{\n    \"kernel_id\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n}\n```\n\nYou will receive a kernel_id, which is the unique identifier for the Python box. If a kernel_id is returned after creation, it indicates that the creation was successful.\n\n#### List Python SandBox\nThe current Python environments that have been created can be queried in the following way.\n```commandline\n$ curl http://127.0.0.1:9501/sandbox \\\n-H \"API-KEY: your-api-key\"\n```\n```json\n{\n  \"kernel_ids\":[\n    \"kernel_id_1\", \n    \"kernel_id_2\", \n    \"...\", \n    \"kernel_id_n\"]\n}\n```\n\n\n\n#### Execute Python Code\nYou can now execute Python code in this Python Box\uff1a\n```commandline\n$ curl http://127.0.0.1:9501/execute \\\n-H \"API-KEY: your-api-key\" \\\n-H \"Content-Type: application/json; charset=utf-8\" \\\n-H \"KERNEL-ID: your-kernel-id\" \\\n-d '{\n    \"code\": \"print(\\\"Hello, Pandora Box!\\\")\"\n}'\n```\n```json\n{\n  \"results\": [],\n  \"logs\": {\n    \"stdout\": [\"Hello, Pandora Box!\"],\n    \"stderr\": []\n  },\n  \"error\": null\n}\n```\n\n`results` has base64 encoded image, if you use matplotlib to plot a picture.\n\n`logs` printed to stdout and stderr during execution. Examples of logs are print statements, warnings, subprocess output, etc. It contains two fields:\n- `stdout`: List of strings, each string is a line printed to stdout.\n- `stderr`: List of strings, each string is a line printed to stderr.\n\n`error` message, if there was an error during execution of the cell. It contains three fields:\n\n- `name`: Name of the error, e.g. NameError, ValueError, etc.\n- `value`: Value of the error, e.g. name 'non_existent_variable' is not defined, etc.\n- `traceback`: Traceback of the error.\n\n#### Close Python Sandbox\nWhen you don't need to use the Python environment, you can close it in time to reduce resource waste.\n\n```commandline\n$ curl http://127.0.0.1:9501/close \\\n-H \"API-KEY: your-api-key\" \\\n-H \"KERNEL-ID: your-kernel-id\"\n```\n```json\n{\n  \"message\": \"Sandbox Closed.\"\n}\n```\n\nEach kernel, if not manually closed, will automatically shut down after 6 hours. This means that the maximum duration for each kernel is 6 hours. This is to avoid wasting resources. The current version does not support duration settings yet.\n\n### Python Script\nYou can directly import the pbox package in your Python script for use. If you don't need any Python environment management or API KEY authentication features, you can directly use CodeSandBox to create a Python environment and execute the code.\n```python\nfrom pbox import CodeSandBox\n\ncode_sandbox = CodeSandBox()\nresult = code_sandbox.execute_code(\"print('Hello, PandaroBox!')\")\n\nprint(str(result))\nprint(result.logs.stdout)\n```\n```text\nResult(results=[], logs=Logs(stdout=['Hello, PandaroBox!'], stderr=[]), error=None)\n['Hello, PandaroBox!']\n```\n\nThe returned result is a `Result` class, which you can view the specific content by using `str()`. The `results` contained within the `Result` is a list. `Logs` is also a class similar to `Result`, containing two lists: `stdout` and `stderr`. The `error` is `null` when the code executes normally, and it is an `Error` class when there is a code error, containing three attributes: `name`, `value`, and `traceback`. The values in `Result`, `Logs`, and `Error` can be accessed using the `.` operator, such as `result.logs.stdout`.\n\n`CodeSandBox` has the ability to remember the context of Python code until it is closed.\n```python\nfrom pbox import CodeSandBox\n\ncode_sandbox = CodeSandBox()\ncode_sandbox.execute_code(\"x = 'Hello, PandoraBox!'\")\nresult = code_sandbox.execute_code(\"print(x)\")\n\nprint(str(result))\n```\n```text\nResult(results=[], logs=Logs(stdout=['Hello, PandoraBox!'], stderr=[]), error=None)\n```\nIf you no longer need it, you can directly close it.\n\n```python\ncode_sandbox.close()\n```\n\nIf you require an API KEY authentication mechanism and the mechanism for kernels to automatically close after 6 hours, you can use `CodeSandBoxManager` to create and close sandboxes as well as execute code.\n```python\nfrom pbox import CodeSandBoxManager\n\ncsb_manager = CodeSandBoxManager()\n\n# creqte sandbox\nkernel_id = csb_manager.create_sandbox(\"your-api-key\")\n\n# list sandbox\ncsb_manager.get_sandbox(\"your-api-key\")\n\n# execute code\nresult = csb_manager.execute_code (\n    \"your-api-key\",\n    \"your-kernel-id\",\n    \"print('Hello, Pandaro Box!')\"\n)\n\n# close sandbox, If you forget, it will automatically close after 6 hours.\ncsb_manager.close_sandbox(\n    \"your-api-key\",\n    \"your-kernel-id\"\n)\n```\n\n## Contributing\nFeel free to contribute to this project. You can open an issue or submit a pull request.\n\n## Contact info\nYou can contact at pydaxing@gmail.com\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Pandora Box Is All You Need. You Can Create Python Environment, Execute Python, Close Python Environment Freely and Easily.",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/pydaxing/PandoraBox"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39d0d6902e610420494503aaf091efdb1e5a308764a2bb6ffa22f2c04b0bc923",
                "md5": "3227e54bd0bf4d124964d23c5faa3615",
                "sha256": "8d73c79658ee8edaa78cec2d68f16226b4f8dc340b89bc1cd1def86aec15c2aa"
            },
            "downloads": -1,
            "filename": "PandoraBox-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3227e54bd0bf4d124964d23c5faa3615",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 12103,
            "upload_time": "2024-10-29T07:35:15",
            "upload_time_iso_8601": "2024-10-29T07:35:15.378685Z",
            "url": "https://files.pythonhosted.org/packages/39/d0/d6902e610420494503aaf091efdb1e5a308764a2bb6ffa22f2c04b0bc923/PandoraBox-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff5f2bdc5abcbf24a6a489889e3531cbdcdfe2b3bd0ef8e3a352e6f513614620",
                "md5": "7544e42fe53a1b4f6b7f9c0973eccad2",
                "sha256": "c69d4cf7f6380a3690c17e6fdcda464cc5ec480bc6df4b5db7a8222feab649d9"
            },
            "downloads": -1,
            "filename": "pandorabox-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7544e42fe53a1b4f6b7f9c0973eccad2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11117,
            "upload_time": "2024-10-29T07:35:17",
            "upload_time_iso_8601": "2024-10-29T07:35:17.007544Z",
            "url": "https://files.pythonhosted.org/packages/ff/5f/2bdc5abcbf24a6a489889e3531cbdcdfe2b3bd0ef8e3a352e6f513614620/pandorabox-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-29 07:35:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pydaxing",
    "github_project": "PandoraBox",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pandorabox"
}
        
Elapsed time: 0.37795s