mattermostautodriver


Namemattermostautodriver JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/embl-bio-it/python-mattermost-autodriver
SummaryA Python Mattermost Auto Driver
upload_time2023-12-01 19:29:07
maintainer
docs_urlNone
authorRenato Alves, Christian Plümer
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
.. image:: https://img.shields.io/pypi/v/mattermostautodriver.svg
    :target: https://pypi.python.org/pypi/mattermostautodriver

.. image:: https://img.shields.io/pypi/l/mattermostautodriver.svg
    :target: https://pypi.python.org/pypi/mattermostautodriver

.. image:: https://img.shields.io/pypi/pyversions/mattermostautodriver.svg
    :target: https://pypi.python.org/pypi/mattermostautodriver

Python Mattermost Auto Driver (APIv4)
=====================================

Info
----

The repository will try to keep up with the ``api`` specification in https://github.com/mattermost/mattermost/ (subfolder ``api``)
Changes in API of ``mattermostautodriver`` will likely be due to a change in the reference mattermost API documentation.

This project is forked from https://github.com/Vaelor/python-mattermost-driver but uses an automatic approach to generate all Python endpoint files from the mattermost OpenAPI specification.

Python 3.6 or later is required.

.. warning::
   This repository generates code in a fully automated fashion based on the API specification provided by mattermost developers.
   No additional effort of backwards compatibility is made.

Versions and Releases
---------------------

Due to frequent API breaking changes, the versioning scheme used by this repository is not strict `SemanticVersioning <https://semver.org/>`_.
Instead, the following should be considered for changes in MAJOR.MINOR.PATCH version digits:

- PATCH: includes bugfixes, non-breaking changes or addition of new endpoints
- MINOR: includes breaking changes such as removal of single endpoints
- MAJOR: includes breaking changes including removal of entire modules or collections of endpoints

In production environments you are advised to pin to the MINOR digit (e.g. 1.3.x).

Installation
------------

.. inclusion-marker-start-install

``pip install mattermostautodriver``

.. inclusion-marker-end-install

Documentation
-------------

Documentation can be found at https://embl-bio-it.github.io/python-mattermost-autodriver/ .

Usage
-----

.. inclusion-marker-start-usage

.. code:: python

    from mattermostautodriver import Driver

    foo = Driver({
        """
        Required options

        Instead of the login/password, you can also use a personal access token.
        If you have a token, you don't need to pass login/pass.
        It is also possible to use 'auth' to pass a auth header in directly,
        for an example, see:
        https://embl-bio-it.github.io/python-mattermost-autodriver/#authentication
        """
        'url': 'mattermost.server.com',
        'login_id': 'user.name',
        'password': 'verySecret',
        'token': 'YourPersonalAccessToken',

        """
        Optional options

        These options already have useful defaults or are just not needed in every case.
        In most cases, you won't need to modify these, especially the basepath.
        If you can only use a self signed/insecure certificate, you should set
        verify to your CA file or to False. Please double check this if you have any errors while
        using a self signed certificate!
        """
        'scheme': 'https',
        'port': 8065,
        'basepath': '',
        'verify': True,  # Or /path/to/file.pem
        'mfa_token': 'YourMFAToken',
        """
        Setting this will pass the your auth header directly to
        the request libraries 'auth' parameter.
        You probably only want that, if token or login/password is not set or
        you want to set a custom auth header.
        """
        'auth': None,
        """
        If for some reasons you get regular timeouts after a while, try to decrease
        this value. The websocket will ping the server in this interval to keep the connection
        alive.
        If you have access to your server configuration, you can of course increase the timeout
        there.
        """
        'timeout': 30,

        """
        This value controls the request timeout.
        See https://python-requests.org/en/master/user/advanced/#timeouts
        for more information.
        The default value is None here, because it is the default in the
        request library, too.
        """
        'request_timeout': None,

        """
        To keep the websocket connection alive even if it gets disconnected for some reason you
        can set the  keepalive option to True. The keepalive_delay defines how long to wait in seconds
        before attempting to reconnect the websocket.
        """
        'keepalive': False,
        'keepalive_delay': 5,

        """
        This option allows you to provide additional keyword arguments when calling websockets.connect()
        By default it is None, meaning we will not add any additional arguments. An example of an
        additional argument you can pass is one used to  disable the client side pings:
        'websocket_kw_args': {"ping_interval": None},
        """
        'websocket_kw_args': None,

        """
        Setting debug to True, will activate a very verbose logging.
        This also activates the logging for the requests package,
        so you can see every request you send.

        Be careful. This SHOULD NOT be active in production, because this logs a lot!
        Even the password for your account when doing driver.login()!
        """
        'debug': False
    })

    """
    Most of the requests need you to be logged in, so calling login()
    should be the first thing you do after you created your Driver instance.
    login() returns the raw response.
    If using a personal access token, you still need to run login().
    In this case, does not make a login request, but a `get_user('me')`
    and sets everything up in the client.
    """
    foo.login()

    """
    You can make api calls by using calling `Driver.endpointofchoice`.
    Using api[''] is deprecated for 5.0.0!

    So, for example, if you used `Driver.api['users'].get_user('me')` before,
    you now just do `Driver.users.get_user('me')`.
    The names of the endpoints and requests are almost identical to
    the names on the api.mattermost.com/v4 page.
    API calls always return the json the server send as a response.
    """
    foo.users.get_user_by_username('another.name')

    """
    If the api request needs additional parameters
    you can pass them to the function in the following way:
    - Path parameters are always simple parameters you pass to the function
    """
    foo.users.get_user(user_id='me')

    # - Query parameters are always passed by passing a `params` dict to the function
    foo.teams.get_teams(params={...})

    # - Request Bodies are always passed by passing an `options` dict or array to the function
    foo.channels.create_channel(options={...})

    # See the mattermost api documentation to see which parameters you need to pass.
    foo.channels.create_channel(options={
        'team_id': 'some_team_id',
        'name': 'awesome-channel',
        'display_name': 'awesome channel',
        'type': 'O'
    })

    """
    If you want to make a websocket connection to the mattermost server
    you can call the init_websocket method, passing an event_handler.
    Every Websocket event send by mattermost will be send to that event_handler.
    See the API documentation for which events are available.
    """
    foo.init_websocket(event_handler)

    # Use `disconnect()` to disconnect the websocket
    foo.disconnect()

    # To upload a file you will need to pass a `files` dictionary
    channel_id = foo.channels.get_channel_by_name_and_team_name('team', 'channel')['id']
    file_id = foo.files.upload_file(
        channel_id=channel_id,
        files={'files': (filename, open(filename, 'rb'))}
    )['file_infos'][0]['id']


    # track the file id and pass it in `create_post` options, to attach the file
    foo.posts.create_post(options={
        'channel_id': channel_id,
        'message': 'This is the important file',
        'file_ids': [file_id]})

    # If needed, you can make custom requests by calling `make_request`
    foo.client.make_request('post', '/endpoint', options=None, params=None, data=None, files=None, basepath=None)

    # If you want to call a webhook/execute it use the `call_webhook` method.
    # This method does not exist on the mattermost api AFAIK, I added it for ease of use.
    foo.client.call_webhook('myHookId', options) # Options are optional


.. inclusion-marker-end-usage

Updating OpenAPI specification
------------------------------

First we need to obtain Mattermost's API in an OpenAPI JSON.

.. code:: shell

    git clone --depth=1 --filter=tree:0 https://github.com/mattermost/mattermost
    cd mattermost/api
    make build
    ./node_modules/.bin/swagger-cli bundle --outfile openapi.json v4/html/static/mattermost-openapi-v4.yaml
    cd -

With the above commands you will have cloned and created an ``openapi.json`` file that will be used by the conversion script.

First install all required dependencies in a virtual environment.

.. code:: shell

    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt

Finally, with the virtual environment still loaded execute

.. code:: shell

    ./generate_endpoints.sh

to generate the updated endpoint definition.

.. code:: shell

    cd docs
    ./update_endpoints.py

needs to be executed after to update endpoint documentation.

The current API conversion code was designed for Python 3.9.
As it uses Python's AST parser and generator, alongside with `Black <https://github.com/psf/black>`_ different versions of Python may result in some differences in the generated code. Double check with a ``git diff`` once complete.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/embl-bio-it/python-mattermost-autodriver",
    "name": "mattermostautodriver",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Renato Alves, Christian Pl\u00fcmer",
    "author_email": "bio-it@embl.de, github@kuuku.net",
    "download_url": "https://files.pythonhosted.org/packages/c9/cb/da25e8a0538d7de2db6fcbedff2f580b90d1bdde77c93800b1338f1b1485/mattermostautodriver-2.0.0.tar.gz",
    "platform": null,
    "description": "\n.. image:: https://img.shields.io/pypi/v/mattermostautodriver.svg\n    :target: https://pypi.python.org/pypi/mattermostautodriver\n\n.. image:: https://img.shields.io/pypi/l/mattermostautodriver.svg\n    :target: https://pypi.python.org/pypi/mattermostautodriver\n\n.. image:: https://img.shields.io/pypi/pyversions/mattermostautodriver.svg\n    :target: https://pypi.python.org/pypi/mattermostautodriver\n\nPython Mattermost Auto Driver (APIv4)\n=====================================\n\nInfo\n----\n\nThe repository will try to keep up with the ``api`` specification in https://github.com/mattermost/mattermost/ (subfolder ``api``)\nChanges in API of ``mattermostautodriver`` will likely be due to a change in the reference mattermost API documentation.\n\nThis project is forked from https://github.com/Vaelor/python-mattermost-driver but uses an automatic approach to generate all Python endpoint files from the mattermost OpenAPI specification.\n\nPython 3.6 or later is required.\n\n.. warning::\n   This repository generates code in a fully automated fashion based on the API specification provided by mattermost developers.\n   No additional effort of backwards compatibility is made.\n\nVersions and Releases\n---------------------\n\nDue to frequent API breaking changes, the versioning scheme used by this repository is not strict `SemanticVersioning <https://semver.org/>`_.\nInstead, the following should be considered for changes in MAJOR.MINOR.PATCH version digits:\n\n- PATCH: includes bugfixes, non-breaking changes or addition of new endpoints\n- MINOR: includes breaking changes such as removal of single endpoints\n- MAJOR: includes breaking changes including removal of entire modules or collections of endpoints\n\nIn production environments you are advised to pin to the MINOR digit (e.g. 1.3.x).\n\nInstallation\n------------\n\n.. inclusion-marker-start-install\n\n``pip install mattermostautodriver``\n\n.. inclusion-marker-end-install\n\nDocumentation\n-------------\n\nDocumentation can be found at https://embl-bio-it.github.io/python-mattermost-autodriver/ .\n\nUsage\n-----\n\n.. inclusion-marker-start-usage\n\n.. code:: python\n\n    from mattermostautodriver import Driver\n\n    foo = Driver({\n        \"\"\"\n        Required options\n\n        Instead of the login/password, you can also use a personal access token.\n        If you have a token, you don't need to pass login/pass.\n        It is also possible to use 'auth' to pass a auth header in directly,\n        for an example, see:\n        https://embl-bio-it.github.io/python-mattermost-autodriver/#authentication\n        \"\"\"\n        'url': 'mattermost.server.com',\n        'login_id': 'user.name',\n        'password': 'verySecret',\n        'token': 'YourPersonalAccessToken',\n\n        \"\"\"\n        Optional options\n\n        These options already have useful defaults or are just not needed in every case.\n        In most cases, you won't need to modify these, especially the basepath.\n        If you can only use a self signed/insecure certificate, you should set\n        verify to your CA file or to False. Please double check this if you have any errors while\n        using a self signed certificate!\n        \"\"\"\n        'scheme': 'https',\n        'port': 8065,\n        'basepath': '',\n        'verify': True,  # Or /path/to/file.pem\n        'mfa_token': 'YourMFAToken',\n        \"\"\"\n        Setting this will pass the your auth header directly to\n        the request libraries 'auth' parameter.\n        You probably only want that, if token or login/password is not set or\n        you want to set a custom auth header.\n        \"\"\"\n        'auth': None,\n        \"\"\"\n        If for some reasons you get regular timeouts after a while, try to decrease\n        this value. The websocket will ping the server in this interval to keep the connection\n        alive.\n        If you have access to your server configuration, you can of course increase the timeout\n        there.\n        \"\"\"\n        'timeout': 30,\n\n        \"\"\"\n        This value controls the request timeout.\n        See https://python-requests.org/en/master/user/advanced/#timeouts\n        for more information.\n        The default value is None here, because it is the default in the\n        request library, too.\n        \"\"\"\n        'request_timeout': None,\n\n        \"\"\"\n        To keep the websocket connection alive even if it gets disconnected for some reason you\n        can set the  keepalive option to True. The keepalive_delay defines how long to wait in seconds\n        before attempting to reconnect the websocket.\n        \"\"\"\n        'keepalive': False,\n        'keepalive_delay': 5,\n\n        \"\"\"\n        This option allows you to provide additional keyword arguments when calling websockets.connect()\n        By default it is None, meaning we will not add any additional arguments. An example of an\n        additional argument you can pass is one used to  disable the client side pings:\n        'websocket_kw_args': {\"ping_interval\": None},\n        \"\"\"\n        'websocket_kw_args': None,\n\n        \"\"\"\n        Setting debug to True, will activate a very verbose logging.\n        This also activates the logging for the requests package,\n        so you can see every request you send.\n\n        Be careful. This SHOULD NOT be active in production, because this logs a lot!\n        Even the password for your account when doing driver.login()!\n        \"\"\"\n        'debug': False\n    })\n\n    \"\"\"\n    Most of the requests need you to be logged in, so calling login()\n    should be the first thing you do after you created your Driver instance.\n    login() returns the raw response.\n    If using a personal access token, you still need to run login().\n    In this case, does not make a login request, but a `get_user('me')`\n    and sets everything up in the client.\n    \"\"\"\n    foo.login()\n\n    \"\"\"\n    You can make api calls by using calling `Driver.endpointofchoice`.\n    Using api[''] is deprecated for 5.0.0!\n\n    So, for example, if you used `Driver.api['users'].get_user('me')` before,\n    you now just do `Driver.users.get_user('me')`.\n    The names of the endpoints and requests are almost identical to\n    the names on the api.mattermost.com/v4 page.\n    API calls always return the json the server send as a response.\n    \"\"\"\n    foo.users.get_user_by_username('another.name')\n\n    \"\"\"\n    If the api request needs additional parameters\n    you can pass them to the function in the following way:\n    - Path parameters are always simple parameters you pass to the function\n    \"\"\"\n    foo.users.get_user(user_id='me')\n\n    # - Query parameters are always passed by passing a `params` dict to the function\n    foo.teams.get_teams(params={...})\n\n    # - Request Bodies are always passed by passing an `options` dict or array to the function\n    foo.channels.create_channel(options={...})\n\n    # See the mattermost api documentation to see which parameters you need to pass.\n    foo.channels.create_channel(options={\n        'team_id': 'some_team_id',\n        'name': 'awesome-channel',\n        'display_name': 'awesome channel',\n        'type': 'O'\n    })\n\n    \"\"\"\n    If you want to make a websocket connection to the mattermost server\n    you can call the init_websocket method, passing an event_handler.\n    Every Websocket event send by mattermost will be send to that event_handler.\n    See the API documentation for which events are available.\n    \"\"\"\n    foo.init_websocket(event_handler)\n\n    # Use `disconnect()` to disconnect the websocket\n    foo.disconnect()\n\n    # To upload a file you will need to pass a `files` dictionary\n    channel_id = foo.channels.get_channel_by_name_and_team_name('team', 'channel')['id']\n    file_id = foo.files.upload_file(\n        channel_id=channel_id,\n        files={'files': (filename, open(filename, 'rb'))}\n    )['file_infos'][0]['id']\n\n\n    # track the file id and pass it in `create_post` options, to attach the file\n    foo.posts.create_post(options={\n        'channel_id': channel_id,\n        'message': 'This is the important file',\n        'file_ids': [file_id]})\n\n    # If needed, you can make custom requests by calling `make_request`\n    foo.client.make_request('post', '/endpoint', options=None, params=None, data=None, files=None, basepath=None)\n\n    # If you want to call a webhook/execute it use the `call_webhook` method.\n    # This method does not exist on the mattermost api AFAIK, I added it for ease of use.\n    foo.client.call_webhook('myHookId', options) # Options are optional\n\n\n.. inclusion-marker-end-usage\n\nUpdating OpenAPI specification\n------------------------------\n\nFirst we need to obtain Mattermost's API in an OpenAPI JSON.\n\n.. code:: shell\n\n    git clone --depth=1 --filter=tree:0 https://github.com/mattermost/mattermost\n    cd mattermost/api\n    make build\n    ./node_modules/.bin/swagger-cli bundle --outfile openapi.json v4/html/static/mattermost-openapi-v4.yaml\n    cd -\n\nWith the above commands you will have cloned and created an ``openapi.json`` file that will be used by the conversion script.\n\nFirst install all required dependencies in a virtual environment.\n\n.. code:: shell\n\n    python3 -m venv .venv\n    source .venv/bin/activate\n    pip install -r requirements.txt\n\nFinally, with the virtual environment still loaded execute\n\n.. code:: shell\n\n    ./generate_endpoints.sh\n\nto generate the updated endpoint definition.\n\n.. code:: shell\n\n    cd docs\n    ./update_endpoints.py\n\nneeds to be executed after to update endpoint documentation.\n\nThe current API conversion code was designed for Python 3.9.\nAs it uses Python's AST parser and generator, alongside with `Black <https://github.com/psf/black>`_ different versions of Python may result in some differences in the generated code. Double check with a ``git diff`` once complete.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python Mattermost Auto Driver",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/embl-bio-it/python-mattermost-autodriver"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f38cc2e7d890120c94a0886982117f13c02fa51f87a42910935f023bd132a01",
                "md5": "313ecddb9029646a99137c7203f54c69",
                "sha256": "2f0ae0168fed78dc5aa21dc99c4350b682a0ef9fe8b1a6c79e4ccd0bad6c386d"
            },
            "downloads": -1,
            "filename": "mattermostautodriver-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "313ecddb9029646a99137c7203f54c69",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 65636,
            "upload_time": "2023-12-01T19:29:05",
            "upload_time_iso_8601": "2023-12-01T19:29:05.878464Z",
            "url": "https://files.pythonhosted.org/packages/2f/38/cc2e7d890120c94a0886982117f13c02fa51f87a42910935f023bd132a01/mattermostautodriver-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9cbda25e8a0538d7de2db6fcbedff2f580b90d1bdde77c93800b1338f1b1485",
                "md5": "c0b99344d05fd7c5c3df97575c5d7972",
                "sha256": "e503b4ba600740a82a8b7fbee75f864f9d80f697b1f2cc23c31c85b47f8d38f7"
            },
            "downloads": -1,
            "filename": "mattermostautodriver-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c0b99344d05fd7c5c3df97575c5d7972",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 51153,
            "upload_time": "2023-12-01T19:29:07",
            "upload_time_iso_8601": "2023-12-01T19:29:07.322106Z",
            "url": "https://files.pythonhosted.org/packages/c9/cb/da25e8a0538d7de2db6fcbedff2f580b90d1bdde77c93800b1338f1b1485/mattermostautodriver-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-01 19:29:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "embl-bio-it",
    "github_project": "python-mattermost-autodriver",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "mattermostautodriver"
}
        
Elapsed time: 0.43444s