Package: aiosyncthing
aiosyncthingAsynchronous Python client for theSyncthingREST API.Inspired bypython-syncthing,
some snippets were copied frompython-fumisNOTE: The package is in active development.Not all features of the API are implemented.Installationpip install aiosyncthingUsageimportasynciofromaiosyncthingimportSyncthingasyncdefmain():asyncwithSyncthing("API Key")asclient:# interact with the client herepassif__name__=="__main__":asyncio.run(main())SyncthingSyncthing is the entrypoint class, it acts as an async context manager and provides access to endpoint namespaces.Initializationdef__init__(self,api_key,# your API Keyurl="http://127.0.0.1:8384",# A base URL of the server, https://syncthing.example.com:443/something is also possibletimeout=DEFAULT_TIMEOUT,# Timeout in secondsverify_ssl=True,# Perform SSL verificationloop=None,# event loopsession=None# client session,)...In case if the api_key is invalid,aiosyncthing.exceptions.SyncthingErrorwill be raised on attempt to perform any request exceptclient.system.ping(), this one only raisesaiosyncthing.exceptions.PingError.System namespaceProvides access to theSystem EndpointspingReturns none if ping is successful or raisessyncthing.exceptions.PingErrorawaitclient.system.ping()configReturns a dict with the server config or raisessyncthing.exceptions.SyncthingErrorawaitclient.system.config()statusReturns a dict with the server status or raisessyncthing.exceptions.SyncthingErrorawaitclient.system.status()versionReturns a dict with the server version or raisessyncthing.exceptions.SyncthingErrorawaitclient.system.version()pausePauses synchronization with all devices or with the selected device or raisessyncthing.exceptions.SyncthingError,
in case if passed devices is unknown to the server,syncthing.exceptions.UnknownDeviceErrorwill be raised. Always returnsNoneawaitclient.system.pause()# pause allawaitclient.system.pause(device_id)# eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA"resumeResumes synchronization with all devices or with a selected device or raisessyncthing.exceptions.SyncthingError,
in case if passed devices is unknown to the server,syncthing.exceptions.UnknownDeviceErrorwill be raised. Always returnsNoneawaitclient.system.resume()# resume allawaitclient.system.resume(device_id)# eg: 'MTLMICV-YE72URC-NF4LBO3-2LVPTFZ-LLCZHEZ-2F3OEJS-R6CWZVE-7VXHFQA"Database namespaceProvides access to theDatabase EndpointsstatusReturns a dict with the folder status or raisessyncthing.exceptions.SyncthingError. If the folder id is unknown to
the server,syncthing.exceptions.UnknownFolderErrorwill be raised.awaitclient.database.status(folder_id)# eg: 'GXWxf-3zgnU'Events namespaceProvides access to theEvents EndpointslistenIs an async generator function that listens to theEvent API, yields events one by one and hides the complexity of long polling.
Raisessyncthing.exceptions.SyncthingErrorin case of error, handles timeouts internally and reconnects to the
endpoint.asyncforeventinclient.events.listen():print(event)last_seen_idReturns the id of the last received event of the previous batch.asyncforeventinclient.events.listen():ifevents.last_seen_id==0:continue# skip first batch because it's historical dataLicenseMIT LicenseCopyright (c) 2020 Gleb SinyavskiyPermission 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.