Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
.. ===============LICENSE_START======================================================= .. Acumos CC-BY-4.0 .. =================================================================================== .. Copyright (C) 2017-2018 AT&T Intellectual Property & Tech Mahindra. All rights reserved. .. =================================================================================== .. This Acumos documentation file is distributed by AT&T and Tech Mahindra .. under the Creative Commons Attribution 4.0 International License (the "License"); .. you may not use this file except in compliance with the License. .. You may obtain a copy of the License at .. .. http://creativecommons.org/licenses/by/4.0 .. .. This file is distributed on an "AS IS" BASIS, .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. .. See the License for the specific language governing permissions and .. limitations under the License. .. ===============LICENSE_END=========================================================
|Build Status|
.. |Build Status| image:: https://jenkins.acumos.org/buildStatus/icon?job=python-model-runner-tox-verify-master :target: https://jenkins.acumos.org/job/python-model-runner-tox-verify-master/
The acumos_model_runner
package installs a command line tool acumos_model_runner
for running models created by the Acumos Python client library <https://pypi.org/project/acumos/>
__.
The model runner provides an HTTP API for invoking model methods, as well as a Swagger UI <https://swagger.io/tools/swagger-ui/>
__ for documentation. See the tutorial for more information on usage.
You will need a Python 3.4+ environment in order to install acumos_model_runner
.
You can use Anaconda <https://www.anaconda.com/download/>
__
(preferred) or pyenv <https://github.com/pyenv/pyenv>
__ to install and
manage Python environments.
The acumos_model_runner
package can be installed with pip:
.. code:: bash
$ pip install acumos_model_runner
.. code:: bash
usage: acumos_model_runner [-h] [--host HOST] [--port PORT]
[--workers WORKERS] [--timeout TIMEOUT]
[--cors CORS]
model_dir
positional arguments:
model_dir Directory containing a dumped Acumos Python model
optional arguments:
-h, --help show this help message and exit
--host HOST The interface to bind to
--port PORT The port to bind to
--workers WORKERS The number of gunicorn workers to spawn
--timeout TIMEOUT Time to wait (seconds) before a frozen worker is
restarted
--cors CORS Enables CORS if provided. Can be a domain, comma-
separated list of domains, or *
.. ===============LICENSE_START======================================================= .. Acumos CC-BY-4.0 .. =================================================================================== .. Copyright (C) 2017-2018 AT&T Intellectual Property & Tech Mahindra. All rights reserved. .. =================================================================================== .. This Acumos documentation file is distributed by AT&T and Tech Mahindra .. under the Creative Commons Attribution 4.0 International License (the "License"); .. you may not use this file except in compliance with the License. .. You may obtain a copy of the License at .. .. http://creativecommons.org/licenses/by/4.0 .. .. This file is distributed on an "AS IS" BASIS, .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. .. See the License for the specific language governing permissions and .. limitations under the License. .. ===============LICENSE_END=========================================================
This tutorial demonstrates how to use the Acumos Python model runner with an example model.
An Acumos model must first be defined using the Acumos Python client library <https://pypi.org/project/acumos/>
__. For illustrative purposes, a simple model with deterministic methods is defined below.
.. code:: python
# example_model.py
from collections import Counter
from acumos.session import AcumosSession
from acumos.modeling import Model, List, Dict
def add(x: int, y: int) -> int:
'''Adds two numbers'''
return x + y
def count(strings: List[str]) -> Dict[str, int]:
'''Counts the occurrences of words in `strings`'''
return Counter(strings)
model = Model(add=add, count=count)
session = AcumosSession()
session.dump(model, 'example-model', '.')
Executing example_model.py
results in the following directory:
.. code:: python
.
├── example_model.py
└── example-model
Now the acumos_model_runner
command line tool can be used to run the saved model.
.. code:: bash
$ acumos_model_runner example-model/
[2018-08-08 12:16:57 -0400] [61113] [INFO] Starting gunicorn 19.9.0
[2018-08-08 12:16:57 -0400] [61113] [INFO] Listening at: http://0.0.0.0:3330 (61113)
[2018-08-08 12:16:57 -0400] [61113] [INFO] Using worker: sync
[2018-08-08 12:16:57 -0400] [61151] [INFO] Booting worker with pid: 61151
The model HTTP API can be explored via its generated Swagger UI. The Swagger UI of example-model
above can be accessed by navigating to http://localhost:3330
in your web browser.
Below are some screenshots of the Swagger UI for example-model
.
The Swagger UI enumerates model method APIs, as well as APIs for accessing model artifacts. Below, the APIs corresponding to the add
and count
methods are listed under the methods
tag.
|Model APIs|
.. |Model APIs| image:: https://gerrit.acumos.org/r/gitweb?p=python-model-runner.git;a=blob_plain;f=docs/tutorial/example-model-apis.png;hb=HEAD
Expanding the documentation for the count
method reveals more information on how to invoke the API.
|Model Method|
.. |Model Method| image:: https://gerrit.acumos.org/r/gitweb?p=python-model-runner.git;a=blob_plain;f=docs/tutorial/example-model-method.png;hb=HEAD
The Swagger UI provides an input form that can be used to try out the count
API with sample data.
|Model Method Request|
.. |Model Method Request| image:: https://gerrit.acumos.org/r/gitweb?p=python-model-runner.git;a=blob_plain;f=docs/tutorial/example-model-request.png;hb=HEAD
The response from the count
API shows that everything is working as expected!
|Model Method Response|
.. |Model Method Response| image:: https://gerrit.acumos.org/r/gitweb?p=python-model-runner.git;a=blob_plain;f=docs/tutorial/example-model-response.png;hb=HEAD
.. ===============LICENSE_START============================================================ .. Acumos CC-BY-4.0 .. ======================================================================================== .. Copyright (C) 2017-2020 AT&T Intellectual Property & Tech Mahindra. All rights reserved. .. Modifications Copyright (C) 2020 Nordix Foundation. .. ======================================================================================== .. This Acumos documentation file is distributed by AT&T and Tech Mahindra .. under the Creative Commons Attribution 4.0 International License (the "License"); .. you may not use this file except in compliance with the License. .. You may obtain a copy of the License at .. .. http://creativecommons.org/licenses/by/4.0 .. .. This file is distributed on an "AS IS" BASIS, .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. .. See the License for the specific language governing permissions and .. limitations under the License. .. ===============LICENSE_END==============================================================
ACUMOS-4164 <https://jira.acumos.org/browse/ACUMOS-4164>
_ACUMOS-4010 <https://jira.acumos.org/browse/ACUMOS-4010>
_ACUMOS-3956 <https://jira.acumos.org/browse/ACUMOS-3956>
_ACUMOS-3161 <https://jira.acumos.org/browse/ACUMOS-3161>
_application/json
via Content-Type
and Accept
headersOpenAPI Specification <https://swagger.io/docs/specification/2-0/basic-structure/>
__ and Swagger UI <https://swagger.io/tools/swagger-ui/>
__Acumos Python client <https://pypi.org/project/acumos/>
__ project.. ===============LICENSE_START======================================================= .. Acumos CC-BY-4.0 .. =================================================================================== .. Copyright (C) 2017-2018 AT&T Intellectual Property & Tech Mahindra. All rights reserved. .. =================================================================================== .. This Acumos documentation file is distributed by AT&T and Tech Mahindra .. under the Creative Commons Attribution 4.0 International License (the "License"); .. you may not use this file except in compliance with the License. .. You may obtain a copy of the License at .. .. http://creativecommons.org/licenses/by/4.0 .. .. This file is distributed on an "AS IS" BASIS, .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. .. See the License for the specific language governing permissions and .. limitations under the License. .. ===============LICENSE_END=========================================================
We use a combination of tox
, pytest
, and flake8
to test
acumos_model_runner
. Code which is not PEP8 compliant (aside from E501) will be
considered a failing test. You can use tools like autopep8
to
“clean” your code as follows:
.. code:: bash
$ pip install autopep8
$ cd python-model-runner
$ autopep8 -r --in-place --ignore E501 acumos_model_runner/ testing/ examples/
Run tox directly:
.. code:: bash
$ cd python-model-runner
$ tox
You can also specify certain tox environments to test:
.. code:: bash
$ tox -e py34 # only test against Python 3.4
$ tox -e flake8 # only lint code
And finally, you can run pytest directly in your environment (recommended starting place):
.. code:: bash
$ pytest
$ pytest -s # verbose output
FAQs
Acumos model runner for Python models
We found that acumos-model-runner demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.