|
| 1 | +.. _ref_server: |
| 2 | + |
| 3 | +SAServer Reference |
| 4 | +====================================== |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + |
| 8 | +The SAServer provides interface to create web API and run in development or production servers. |
| 9 | + |
| 10 | +This will create a directory by the given name in your current or provided directory: |
| 11 | + |
| 12 | +.. code-block:: bash |
| 13 | +
|
| 14 | + superannotatecli create-server --name <directory_name> --path <directory_path> |
| 15 | +
|
| 16 | +---------- |
| 17 | + |
| 18 | +Usage |
| 19 | +---------------- |
| 20 | + |
| 21 | +SuperAnnotate Python SDK allows access to the platform without web browser: |
| 22 | + |
| 23 | +.. code-block:: python |
| 24 | +
|
| 25 | + import random |
| 26 | + from superannotate import SAClient |
| 27 | + from superannotate import SAServer |
| 28 | +
|
| 29 | +
|
| 30 | + app = SAServer() |
| 31 | + sa_client = SAClient() |
| 32 | + QA_EMAILS = [ |
| 33 | + 'qa1@superannotate.com', 'qa2@superannotate.com', |
| 34 | + 'qa3@superannotate.com', 'qa4@superannotate.com' |
| 35 | + ] |
| 36 | +
|
| 37 | +
|
| 38 | + @app.route("item_completed", methods=["POST"]) |
| 39 | + def index(request): |
| 40 | + """ |
| 41 | + Listening webhooks on items completed events form Superannotate automation |
| 42 | + and is randomly assigned to qa |
| 43 | + """ |
| 44 | + project_id, folder_id = request.data['project_id'], request.data['folder_id'] |
| 45 | + project = sa_client.get_project_by_id(project_id) |
| 46 | + folder = sa_client.get_folder_by_id(project_id=project_id, folder_id=folder_id) |
| 47 | + sa_client.assign_items( |
| 48 | + f"{project['name']}/{folder['name']}", |
| 49 | + items=[request.data['name']], |
| 50 | + user=random.choice(QA_EMAILS) |
| 51 | + ) |
| 52 | +
|
| 53 | +
|
| 54 | + if __name__ == '__main__': |
| 55 | + app.run(host='0.0.0.0', port=5002) |
| 56 | +
|
| 57 | +Interface |
| 58 | +---------------- |
| 59 | + |
| 60 | +.. automethod:: superannotate.SAServer.route |
| 61 | +.. automethod:: superannotate.SAServer.add_url_rule |
| 62 | +.. automethod:: superannotate.SAServer.run |
| 63 | + |
| 64 | + |
| 65 | +uWSGI |
| 66 | +---------- |
| 67 | + |
| 68 | +`uWSGI`_ is a fast, compiled server suite with extensive configuration |
| 69 | +and capabilities beyond a basic server. |
| 70 | + |
| 71 | +* It can be very performant due to being a compiled program. |
| 72 | +* It is complex to configure beyond the basic application, and has so |
| 73 | + many options that it can be difficult for beginners to understand. |
| 74 | +* It does not support Windows (but does run on WSL). |
| 75 | +* It requires a compiler to install in some cases. |
| 76 | + |
| 77 | +This page outlines the basics of running uWSGI. Be sure to read its |
| 78 | +documentation to understand what features are available. |
| 79 | + |
| 80 | +.. _uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/ |
| 81 | + |
| 82 | +uWSGI has multiple ways to install it. The most straightforward is to |
| 83 | +install the ``pyuwsgi`` package, which provides precompiled wheels for |
| 84 | +common platforms. However, it does not provide SSL support, which can be |
| 85 | +provided with a reverse proxy instead. |
| 86 | + |
| 87 | +Install ``pyuwsgi``. |
| 88 | + |
| 89 | +.. code-block:: text |
| 90 | +
|
| 91 | + $ pip install pyuwsgi |
| 92 | +
|
| 93 | +If you have a compiler available, you can install the ``uwsgi`` package |
| 94 | +instead. Or install the ``pyuwsgi`` package from sdist instead of wheel. |
| 95 | +Either method will include SSL support. |
| 96 | + |
| 97 | +.. code-block:: text |
| 98 | +
|
| 99 | + $ pip install uwsgi |
| 100 | +
|
| 101 | + # or |
| 102 | + $ pip install --no-binary pyuwsgi pyuwsgi |
| 103 | +
|
| 104 | +
|
| 105 | +Running |
| 106 | +------- |
| 107 | + |
| 108 | +The most basic way to run uWSGI is to tell it to start an HTTP server |
| 109 | +and import your application. |
| 110 | + |
| 111 | +.. code-block:: text |
| 112 | +
|
| 113 | + $ uwsgi --http 127.0.0.1:8000 --master -p 4 -w wsgi:app |
| 114 | +
|
| 115 | + *** Starting uWSGI 2.0.20 (64bit) on [x] *** |
| 116 | + *** Operational MODE: preforking *** |
| 117 | + spawned uWSGI master process (pid: x) |
| 118 | + spawned uWSGI worker 1 (pid: x, cores: 1) |
| 119 | + spawned uWSGI worker 2 (pid: x, cores: 1) |
| 120 | + spawned uWSGI worker 3 (pid: x, cores: 1) |
| 121 | + spawned uWSGI worker 4 (pid: x, cores: 1) |
| 122 | + spawned uWSGI http 1 (pid: x) |
0 commit comments