{ "info": { "author": "Coumes Quentin", "author_email": "coumes.quentin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "[![Build Status](https://travis-ci.org/qcoumes/sandbox-api.svg?branch=master)](https://travis-ci.org/qcoumes/sandbox-api)\n[![codecov](https://codecov.io/gh/qcoumes/sandbox-api/branch/master/graph/badge.svg)](https://codecov.io/gh/qcoumes/sandbox-api)\n[![CodeFactor](https://www.codefactor.io/repository/github/qcoumes/sandbox-api/badge)](https://www.codefactor.io/repository/github/qcoumes/sandbox-api)\n[![PyPI Version](https://badge.fury.io/py/sandbox-api.svg)](https://badge.fury.io/py/sandbox-api)\n[![Python 3.5+](https://img.shields.io/badge/python-3.5+-brightgreen.svg)](#)\n[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/qcoumes/sandbox-api/blob/master/LICENSE)\n\n# Python API for WIMS' adm/raw module\n\nA Python 3 interface to communicate with a [sandbox](https://github.com/PremierLangage/sandbox)\n\n\n## Installation\n\nThe latest stable version is available on [PyPI](https://pypi.org/project/sandbox-api/) :\n\n```bash\npip install sandbox-api\n```\n\nor from the sources:\n\n```bash\ngit clone https://github.com/qcoumes/sandbox-api\ncd sandbox-api\npython3 setup.py install\n```\n \n \n ## Usage\n \n Sandbox-api is pretty straightforward to use, you just need to import Sandbox and create\n an instance with the url of the server :\n \n ```python\nfrom sandbox_api import Sandbox\n\ns = Sandbox(\"http://www.my-sandbox.com\")\n```\n\n### Specifications and libraries\n\nThe specs of the sandbox and the libraries installed are available as attributes:\n\n```python\ns.cpu\n{'count': 1, 'period': 1000, 'shares': 1024, 'quota': 0, 'name': 'Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz'}\n\ns.containers\n{'total': 5, 'running': 0, 'available': 5}\n\ns.python3\n'3.7.3'\n\ns.python2\n'2.7.16'\n```\n\nAttribute other than 'url' are retrieved from the sandbox at first access, attribute are\nseparated in two categories, specifications and libraries. Every attribute of one category are\nretrieved the first time an attribute of the corresponding category is accessed.\n\nThese attributes are fetch through HTTP requests, this can take some times (should be no more\nthan 2 seconds), especially for the libraries category.\n\nNote that attributes are cached (except for 'containers'), and subsequent access to one category\nare instantaneous.\n\nAvailable attributes are:\n\n* Specifications\n * sandbox_version (str): Version of the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * docker_version (str): Version of docker used by the sandbox formatted as 'MAJOR.MINOR.PATCH'\n * containers (dict): Dict containing the status of the containers running on the sandbox.\n * memory (dict): Memory limits for each containers on the sandbox.\n * cpu (dict): CPU information for each containers on the sandbox.\n * environ (dict): Environments variables use in the containers.\n * execute_timeout (Union[int, float]): Time in seconds before an 'execute/' request timeout.\n * expiration (int): Time in before an environment expire on the sandbox.\n* Libraries\n * python3 (str): Version of python3 used by the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * python2 (str): Version of python2 used by the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * java (str): Version of java used by the sandbox formatted as 'JDK MAJOR.MINOR'.\n * gcc (str): Version of gcc used by the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * gpp (str): Version of g++ used by the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * perl (str): Version of perl used by the sandbox formatted as 'MAJOR.MINOR.PATCH'.\n * postgres (str): Version of postgres used by the sandbox formatted as 'MAJOR.MINOR'.\n * libraries (dict): Dict containing :\n * system (dict): The installed packages (dpkg).\n * c (dict): The installed libraries and their version.\n * python (dict): The installed python modules.\n * perl (dict): The installed perl modules.\n * bin (dict): Every command available in PATH on the sandbox\n\n\n### Sandbox current load\n\nIt is possible to obtain the current load of the sandbox with the `usage()` method.\nIt returns a float between 0 and 1, indicating the current charge on the sandbox, 0 means that the\nsandbox is currently unused, 1 means that it is used a full capacity and an 'execute/' request will\nprobably be delayed.\n\n```python\ns.usage()\n0.2\n```\n\n\n### Downloading environments and files\n\nYou can download files or environments through the `download(uuid, path=None)` method. `uuid`\ncorrespond to the ID of the environment on the sandbox.\n\nIf only uuid is provided the whole environment will be downloading, if path is also provided, only\nthe file corresponding to path inside the environment will be downloaded.\n\nThe downloaded object is returned as a `io.BytesIO`.\n\n\n### Executing commands\n\nUse the `execute(config, environ=None)` method to execute commands on the sandbox. Config\nmust be a dictionary corresponding to a valid config as defined\n[here](https://documenter.getpostman.com/view/7955851/S1a915EG?version=latest#872b604c-9cce-42e2-8888-9a0311f3a724),\nenviron, if provided, must be a binary object implementing the `.read()` (I.G. `file object` or\n`io.BytesIO`) at position 0 corresponding to a valid environment (again, more information\n[here](https://documenter.getpostman.com/view/7955851/S1a915EG?version=latest#872b604c-9cce-42e2-8888-9a0311f3a724)).\n\nThe returned value is a dictionary corresponding to the response's json :\n\nYou can check a config dictionnary by calling `sandbox_api.utils.validate(config)`.\n\n```python\ns.execute({\n \"commands\": [\n \"echo $((2+2))\"\n ]\n})\n\n{\n 'status': 0,\n 'execution': [\n {\n 'command': 'echo $((2+2))',\n 'exit_code': 0,\n 'stdout': '4',\n 'stderr': '',\n 'time': 0.28589797019958496\n }\n ],\n 'total_time': 0.2871053218841553\n}\n```\n\n## Exceptions\n\nSince sandbox-api rely on HTTP, any response with a status code greater or equal to 300 will raise\na corresponding exception `Sanbox{STATUS}` the response (a `requests.Response` object) received is\navailable in the `response` attribute of the exception.\n\nAll of these exceptions inherit `SandboxError`.\n\n```python\nfrom sandbox_api import SandboxError, Sandbox404\n\ntry:\n file = s.download(\"872b604c-9cce-42e2-8888-9a0311f3a724\", \"unknown\")\nexcept Sandbox404:\n print(\"'unknown' does not exists in environment '872b604c-9cce-42e2-8888-9a0311f3a724'\")\nexcept SandboxError as e:\n print(\"Sandbox responded with a '%d' status code\" % e.response.status_code)\n```\n\n______\n\n# Changelog\n\n\n#### 0.0.5\n\n* Added method `check()` to `Sandbox` to check if an environment/file exists on the sandbox.\n\n\n#### 0.0.4\n\n* Added function `validate()` to check a config dict in `sandbox_api.utils`.\n\n\n#### 0.0.3\n\n* Added missing type hints `cpu` for `Sandbox`\n\n\n#### 0.0.2\n\n* Added type hints for `Sandbox`'s attributes.\n\n\n#### 0.0.1\n\n* Initial release", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/qcoumes/sandbox-api", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "sandbox-api", "package_url": "https://pypi.org/project/sandbox-api/", "platform": "", "project_url": "https://pypi.org/project/sandbox-api/", "project_urls": { "Homepage": "https://github.com/qcoumes/sandbox-api" }, "release_url": "https://pypi.org/project/sandbox-api/0.0.5/", "requires_dist": null, "requires_python": "", "summary": "Provide a Python 3 interface to communicate with a sandbox (https://github.com/PremierLangage/sandbox)", "version": "0.0.5" }, "last_serial": 5872639, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "078b9b7c0094b32e0b7d49bfe1b042b6", "sha256": "b5d8c6d070e88560d0f3bb71ab3302a2dca5a3c67bdb52336d054e97ac317351" }, "downloads": -1, "filename": "sandbox-api-0.0.1.tar.gz", "has_sig": false, "md5_digest": "078b9b7c0094b32e0b7d49bfe1b042b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6657, "upload_time": "2019-08-21T21:25:58", "url": "https://files.pythonhosted.org/packages/e3/81/fba574bc548eefa9a52c3e520ec90ca5a673388005ef54dfeba6ee283cb6/sandbox-api-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "1d557621e22ba806dfd3eb8870fe2a9f", "sha256": "c8ab3a037ea42eb7b5f071d6a5d880db65d17da7754ad70a8530b8239f847629" }, "downloads": -1, "filename": "sandbox-api-0.0.2.tar.gz", "has_sig": false, "md5_digest": "1d557621e22ba806dfd3eb8870fe2a9f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6822, "upload_time": "2019-09-05T08:19:11", "url": "https://files.pythonhosted.org/packages/a0/27/713a1908f56b437095d75e4450fc90f6378dca148404e4c0d8e040b5ef34/sandbox-api-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "59059b429b4bb57e10cad7a50b0c517a", "sha256": "1e5466321ab1cec58f53632169a138912db52777ec06b8f7286da61b4dc594e8" }, "downloads": -1, "filename": "sandbox-api-0.0.3.tar.gz", "has_sig": false, "md5_digest": "59059b429b4bb57e10cad7a50b0c517a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6871, "upload_time": "2019-09-05T11:41:42", "url": "https://files.pythonhosted.org/packages/0c/e4/ede7eba60c5b75dcc449f3cbf0695454d57c7a4e874d27e4ccbc7afdd77d/sandbox-api-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "89f8b6492371d7f1cd8687a3812e019b", "sha256": "1091f6b569c7d62e7364d466b3d0420ce44d440f84f0a28df3679709ef358780" }, "downloads": -1, "filename": "sandbox-api-0.0.4.tar.gz", "has_sig": false, "md5_digest": "89f8b6492371d7f1cd8687a3812e019b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8387, "upload_time": "2019-09-11T16:40:01", "url": "https://files.pythonhosted.org/packages/9d/8b/0ba92a1846c301236cce694b570a0ade1f417cb98fb7e6b6de51d5494c7d/sandbox-api-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "8d06a8c68b34724707d6060575504f2b", "sha256": "47981c844d44d5374175fe57bd132574737a1d0c4fed7b95174bff16e87ddadd" }, "downloads": -1, "filename": "sandbox-api-0.0.5.tar.gz", "has_sig": false, "md5_digest": "8d06a8c68b34724707d6060575504f2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8628, "upload_time": "2019-09-23T09:57:23", "url": "https://files.pythonhosted.org/packages/f4/8d/1965a57c155a2382aaadee325db32a87f7231baee164c63534c62287253b/sandbox-api-0.0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8d06a8c68b34724707d6060575504f2b", "sha256": "47981c844d44d5374175fe57bd132574737a1d0c4fed7b95174bff16e87ddadd" }, "downloads": -1, "filename": "sandbox-api-0.0.5.tar.gz", "has_sig": false, "md5_digest": "8d06a8c68b34724707d6060575504f2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8628, "upload_time": "2019-09-23T09:57:23", "url": "https://files.pythonhosted.org/packages/f4/8d/1965a57c155a2382aaadee325db32a87f7231baee164c63534c62287253b/sandbox-api-0.0.5.tar.gz" } ] }