Skip to main content

Asynchronous Python client for the Syncthing REST API

Project description

aiosyncthing

Continuous Integration

Asynchronous Python client for the Syncthing REST API.

Inspired by python-syncthing, some snippets were copied from python-fumis

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

Installation

pip install aiosyncthing

Usage

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

    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

ping

Returns none if ping is successful or raises syncthing.exceptions.PingError

await client.system.ping()

config

Returns a dict with the server config or raises syncthing.exceptions.SyncthingError

await client.system.config()

status

Returns a dict with the server status or raises syncthing.exceptions.SyncthingError

await client.system.status()

version

Returns a dict with the server version or raises syncthing.exceptions.SyncthingError

await client.system.version()

pause

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

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

resume

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

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

status

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.

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

Events namespace

Provides access to the Events Endpoints

listen

Is an async generator function that listens to the Event API, 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.

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

last_seen_id

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiosyncthing-0.6.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

aiosyncthing-0.6.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file aiosyncthing-0.6.3.tar.gz.

File metadata

  • Download URL: aiosyncthing-0.6.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for aiosyncthing-0.6.3.tar.gz
Algorithm Hash digest
SHA256 b1fe869c078e74987b5642db552616ac419a1ea34a6da5afb5ca381f017f81f6
MD5 579dd2212bbd18c857bc9db0646f4625
BLAKE2b-256 1b1effe803fc755599890c280bbc1c626606106281cc91aae4710e56c2160794

See more details on using hashes here.

File details

Details for the file aiosyncthing-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: aiosyncthing-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for aiosyncthing-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1f8f64215c4d2e48ebff59a221aa23827d1c32341e13aa274a03a3356271970f
MD5 d574a9cc8dc2b2592e4daa38691c4a9a
BLAKE2b-256 1160d0e6273c03c9d893926d6b60e598a4cd38bcc0ede83204744c517fb4224e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page