aiosyncthing


Nameaiosyncthing JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/zhulik/aiosyncthing
SummaryAsynchronous Python client for the Syncthing REST API
upload_time2020-08-02 15:18:00
maintainer
docs_urlNone
authorGleb Sinyavskiy
requires_python
licenseThe MIT License
keywords syncthing sync rest backup api aio async await
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiosyncthing

![Continuous Integration](https://github.com/zhulik/aiosyncthing/workflows/Continuous%20Integration/badge.svg?branch=master)

Asynchronous Python client for the [Syncthing](https://syncthing.net/) [REST API](https://docs.syncthing.net/dev/rest.html).

Inspired by [python-syncthing](https://github.com/blakev/python-syncthing),
some snippets were copied from [python-fumis](https://github.com/frenck/python-fumis)

NOTE: The package is in active development. *Not all features of the API are implemented.*

## Installation

`pip install aiosyncthing`

## Usage

```python
import asyncio

from aiosyncthing import Syncthing

async def main():

  async with Syncthing("API Key") as client:
    # interact with the client here
    pass

if __name__ == "__main__":
  asyncio.run(main())
```

### Syncthing

Syncthing is the entrypoint class, it acts as an async context manager and provides access to endpoint namespaces.

#### Initialization

```python
    def __init__(
        self,
        api_key, # your API Key
        url="http://127.0.0.1:8384", # A base URL of the server, https://syncthing.example.com:443/something is also possible
        timeout=DEFAULT_TIMEOUT, # Timeout in seconds
        verify_ssl=True, # Perform SSL verification
        loop=None, # event loop
        session=None # client session,
    )...
```

In case if the api_key is invalid, `aiosyncthing.exceptions.SyncthingError` will be raised on attempt to perform any request except `client.system.ping()`, this one only raises `aiosyncthing.exceptions.PingError`.

### System namespace

Provides access to the [System Endpoints](https://docs.syncthing.net/dev/rest.html#system-endpoints)

#### [ping](https://docs.syncthing.net/rest/system-ping-get.html)
Returns none if ping is successful or raises `syncthing.exceptions.PingError`

```python
await client.system.ping()
```

#### [config](https://docs.syncthing.net/rest/system-config-get.html)
Returns a dict with the server config or raises `syncthing.exceptions.SyncthingError`

```python
await client.system.config()
```

#### [status](https://docs.syncthing.net/rest/system-status-get.html)
Returns a dict with the server status or raises `syncthing.exceptions.SyncthingError`

```python
await client.system.status()
```

#### [version](https://docs.syncthing.net/rest/system-version-get.html)
Returns a dict with the server version or raises `syncthing.exceptions.SyncthingError`

```python
await client.system.version()
```

#### [pause](https://docs.syncthing.net/rest/system-pause-post.html)
Pauses synchronization with all devices or with the selected device or raises `syncthing.exceptions.SyncthingError`,
in case if passed devices is unknown to the server, `syncthing.exceptions.UnknownDeviceError` will be raised. Always returns `None`

```python
await client.system.pause() # pause all
await client.system.pause(device_id) # eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA"
```

#### [resume](https://docs.syncthing.net/rest/system-resume-post.html)
Resumes synchronization with all devices or with a selected device or raises `syncthing.exceptions.SyncthingError`,
in case if passed devices is unknown to the server, `syncthing.exceptions.UnknownDeviceError` will be raised. Always returns `None`

```python
await client.system.resume() # resume all
await client.system.resume(device_id) # eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA"
```

### Database namespace
Provides access to the [Database Endpoints](https://docs.syncthing.net/dev/rest.html#database-endpoints)

#### [status](https://docs.syncthing.net/rest/db-status-get.html)
Returns a dict with the folder status or raises `syncthing.exceptions.SyncthingError`. If the folder id is unknown to
the server, `syncthing.exceptions.UnknownFolderError` will be raised.

```python
await client.database.status(folder_id) # eg: 'GXWxf-3zgnU'
```

### Events namespace
Provides access to the [Events Endpoints](https://docs.syncthing.net/dev/rest.html#event-endpoints)

### listen
Is an async generator function that listens to the [Event API](https://docs.syncthing.net/dev/events.html), yields events one by one and hides the complexity of long polling.
Raises `syncthing.exceptions.SyncthingError` in case of error, handles timeouts internally and reconnects to the
endpoint.


```python
async for event in client.events.listen():
  print(event)
```

### last_seen_id
Returns the id of the last received event of the previous batch.

```python
async for event in client.events.listen():
  if events.last_seen_id == 0:
    continue # skip first batch because it's historical data
```

## License

MIT License

Copyright (c) 2020 Gleb Sinyavskiy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zhulik/aiosyncthing",
    "name": "aiosyncthing",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "syncthing,sync,rest,backup,api,aio,async,await",
    "author": "Gleb Sinyavskiy",
    "author_email": "zhulik.gleb@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ea/99/8b81321fdc130f051ccba1311534bc2b53c8d71cf026e36a87de8d796242/aiosyncthing-0.4.0.tar.gz",
    "platform": "",
    "description": "# aiosyncthing\n\n![Continuous Integration](https://github.com/zhulik/aiosyncthing/workflows/Continuous%20Integration/badge.svg?branch=master)\n\nAsynchronous Python client for the [Syncthing](https://syncthing.net/) [REST API](https://docs.syncthing.net/dev/rest.html).\n\nInspired by [python-syncthing](https://github.com/blakev/python-syncthing),\nsome snippets were copied from [python-fumis](https://github.com/frenck/python-fumis)\n\nNOTE: The package is in active development. *Not all features of the API are implemented.*\n\n## Installation\n\n`pip install aiosyncthing`\n\n## Usage\n\n```python\nimport asyncio\n\nfrom aiosyncthing import Syncthing\n\nasync def main():\n\n  async with Syncthing(\"API Key\") as client:\n    # interact with the client here\n    pass\n\nif __name__ == \"__main__\":\n  asyncio.run(main())\n```\n\n### Syncthing\n\nSyncthing is the entrypoint class, it acts as an async context manager and provides access to endpoint namespaces.\n\n#### Initialization\n\n```python\n    def __init__(\n        self,\n        api_key, # your API Key\n        url=\"http://127.0.0.1:8384\", # A base URL of the server, https://syncthing.example.com:443/something is also possible\n        timeout=DEFAULT_TIMEOUT, # Timeout in seconds\n        verify_ssl=True, # Perform SSL verification\n        loop=None, # event loop\n        session=None # client session,\n    )...\n```\n\nIn case if the api_key is invalid, `aiosyncthing.exceptions.SyncthingError` will be raised on attempt to perform any request except `client.system.ping()`, this one only raises `aiosyncthing.exceptions.PingError`.\n\n### System namespace\n\nProvides access to the [System Endpoints](https://docs.syncthing.net/dev/rest.html#system-endpoints)\n\n#### [ping](https://docs.syncthing.net/rest/system-ping-get.html)\nReturns none if ping is successful or raises `syncthing.exceptions.PingError`\n\n```python\nawait client.system.ping()\n```\n\n#### [config](https://docs.syncthing.net/rest/system-config-get.html)\nReturns a dict with the server config or raises `syncthing.exceptions.SyncthingError`\n\n```python\nawait client.system.config()\n```\n\n#### [status](https://docs.syncthing.net/rest/system-status-get.html)\nReturns a dict with the server status or raises `syncthing.exceptions.SyncthingError`\n\n```python\nawait client.system.status()\n```\n\n#### [version](https://docs.syncthing.net/rest/system-version-get.html)\nReturns a dict with the server version or raises `syncthing.exceptions.SyncthingError`\n\n```python\nawait client.system.version()\n```\n\n#### [pause](https://docs.syncthing.net/rest/system-pause-post.html)\nPauses synchronization with all devices or with the selected device or raises `syncthing.exceptions.SyncthingError`,\nin case if passed devices is unknown to the server, `syncthing.exceptions.UnknownDeviceError` will be raised. Always returns `None`\n\n```python\nawait client.system.pause() # pause all\nawait client.system.pause(device_id) # eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA\"\n```\n\n#### [resume](https://docs.syncthing.net/rest/system-resume-post.html)\nResumes synchronization with all devices or with a selected device or raises `syncthing.exceptions.SyncthingError`,\nin case if passed devices is unknown to the server, `syncthing.exceptions.UnknownDeviceError` will be raised. Always returns `None`\n\n```python\nawait client.system.resume() # resume all\nawait client.system.resume(device_id) # eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA\"\n```\n\n### Database namespace\nProvides access to the [Database Endpoints](https://docs.syncthing.net/dev/rest.html#database-endpoints)\n\n#### [status](https://docs.syncthing.net/rest/db-status-get.html)\nReturns a dict with the folder status or raises `syncthing.exceptions.SyncthingError`. If the folder id is unknown to\nthe server, `syncthing.exceptions.UnknownFolderError` will be raised.\n\n```python\nawait client.database.status(folder_id) # eg: 'GXWxf-3zgnU'\n```\n\n### Events namespace\nProvides access to the [Events Endpoints](https://docs.syncthing.net/dev/rest.html#event-endpoints)\n\n### listen\nIs an async generator function that listens to the [Event API](https://docs.syncthing.net/dev/events.html), yields events one by one and hides the complexity of long polling.\nRaises `syncthing.exceptions.SyncthingError` in case of error, handles timeouts internally and reconnects to the\nendpoint.\n\n\n```python\nasync for event in client.events.listen():\n  print(event)\n```\n\n### last_seen_id\nReturns the id of the last received event of the previous batch.\n\n```python\nasync for event in client.events.listen():\n  if events.last_seen_id == 0:\n    continue # skip first batch because it's historical data\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2020 Gleb Sinyavskiy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n\n",
    "bugtrack_url": null,
    "license": "The MIT License",
    "summary": "Asynchronous Python client for the Syncthing REST API",
    "version": "0.4.0",
    "split_keywords": [
        "syncthing",
        "sync",
        "rest",
        "backup",
        "api",
        "aio",
        "async",
        "await"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "618ea0a4af5c934b1008c60ba43ee193",
                "sha256": "caa7b7c4ce64a66cbf63abab99940a979f2ba99d1216a73a206148d1bbc57ad5"
            },
            "downloads": -1,
            "filename": "aiosyncthing-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "618ea0a4af5c934b1008c60ba43ee193",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8481,
            "upload_time": "2020-08-02T15:17:59",
            "upload_time_iso_8601": "2020-08-02T15:17:59.157622Z",
            "url": "https://files.pythonhosted.org/packages/94/a4/b74f48e4e6fcd3467264d933e4c2f895e8b15cf2bdf3374d45b5efafb671/aiosyncthing-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "371ae364b53536e7c125329157673b60",
                "sha256": "818df6bb281cbb91d27bd00fce361a101231a1d8bb01b9b0564b086bdfc85d09"
            },
            "downloads": -1,
            "filename": "aiosyncthing-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "371ae364b53536e7c125329157673b60",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6047,
            "upload_time": "2020-08-02T15:18:00",
            "upload_time_iso_8601": "2020-08-02T15:18:00.318853Z",
            "url": "https://files.pythonhosted.org/packages/ea/99/8b81321fdc130f051ccba1311534bc2b53c8d71cf026e36a87de8d796242/aiosyncthing-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-02 15:18:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "zhulik",
    "error": "Could not fetch GitHub repository",
    "lcname": "aiosyncthing"
}
        
Elapsed time: 0.12310s