Python bindings to the Syncthing REST interface.

Overview

python-syncthing

pypi Syncthing Documentation Status MIT License

Python bindings to the Syncthing REST interface.

$ pip install syncthing

Getting Started

from syncthing import Syncthing

API_KEY = "..."

s = Syncthing(API_KEY)

# name spaced by API endpoints
s.system.connections()

# supports GET/POST semantics
sync_errors = s.system.errors()
s.system.clear()

if sync_errors:
    for e in sync_errors:
        print(e)

# supports event long-polling
event_stream = s.events(limit=10)
for event in event_stream:
    # do something with `event`
    if event_stream.count > 100:
        event_stream.stop()

Running Tests

The API doctests rely on the following function to run against your instance. None of the "breaking" calls will be tested. You must set the following environment variables otherwise all tests will fail.

def _syncthing():
    KEY = os.getenv('SYNCTHING_API_KEY')
    HOST = os.getenv('SYNCTHING_HOST', '127.0.0.1')
    PORT = os.getenv('SYNCTHING_PORT', 8384)
    IS_HTTPS = bool(int(os.getenv('SYNCTHING_HTTPS', '0')))
    SSL_CERT_FILE = os.getenv('SYNCTHING_CERT_FILE')
    return Syncthing(KEY, HOST, PORT, 10.0, IS_HTTPS, SSL_CERT_FILE)

License

The MIT License (MIT)

Copyright (c) 2015-2017 Blake VandeMerwe

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.

Comments
  • import error with 2.1

    import error with 2.1

    Installed 2.1 with pip install syncthing, but trying from syncthing import Syncthing produces the following error:

    Traceback (most recent call last):
      File "./syncthing", line 3, in <module>
        from syncthing import Syncthing
      File "/usr/local/lib/python2.7/dist-packages/syncthing/__init__.py", line 748
        def __init__(self, *args, last_seen_id=None, filters=None, limit=None, **kwargs):
                                             ^
    SyntaxError: invalid syntax
    

    Reverting the installation back to 2.0.2 works no problem.

    This is on a Debian 8.8 box, using python 2.7.9

    opened by Vo-Shay 3
  • Stop supresssing ConnectionError's in the events generator

    Stop supresssing ConnectionError's in the events generator

    Hello again ;)

    After some experiments with the HASS integration I found out that ConnectionError's must not be swallowed, because in case of missing network connection or a syncthing server being down the generator tries to reconnect in an infinite loop consuming lots of CPU.

    Also, I found out that the library produces a lot of noise in logs, so I disabled some logging, the errors are reraised anyway

    Thank you!

    opened by zhulik 2
  • Use dateutil to replace parse_datetime

    Use dateutil to replace parse_datetime

    Times like 2017-11-09T14:59:48.48534+01:00 would break the original function. Instead of trying to fix it I opted to replace it by a widely used library.

    opened by cbenhagen 2
  • Cannot create 2 Syncthing objects

    Cannot create 2 Syncthing objects

    e.g. a = Syncthing(api_key=1, ...) b = Syncthing(api_key=2, ...)

    Results in calls from object a (e.g. a.sys.config()) to get b's config rather than the expected a's config.

    The issue is caused by the C class having a static variable C.iface which gets overridden when a new Syncthing object is created. As a result, when object a tries to make a new api call, it uses b's iface variable.

    opened by Jvlythical 2
  • Fails to run

    Fails to run

    $ python -m syncthing
    Traceback (most recent call last):
      File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main
        mod_name, loader, code, fname = _get_module_details(mod_name)
      File "/usr/lib/python2.7/runpy.py", line 109, in _get_module_details
        return _get_module_details(pkg_main_name)
      File "/usr/lib/python2.7/runpy.py", line 101, in _get_module_details
        loader = get_loader(mod_name)
      File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader
        return find_loader(fullname)
      File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader
        for importer in iter_importers(fullname):
      File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers
        __import__(pkg)
      File "/usr/local/lib/python2.7/dist-packages/syncthing/__init__.py", line 10, in <module>
        from .syncthing import Syncthing
      File "/usr/local/lib/python2.7/dist-packages/syncthing/syncthing.py", line 100, in <module>
        class Syncthing(with_metaclass(SyncthingType, object)):
      File "/usr/local/lib/python2.7/dist-packages/six.py", line 778, in __new__
        return meta(name, bases, d)
      File "/usr/local/lib/python2.7/dist-packages/syncthing/syncthing.py", line 58, in __init__
        ins_file = get_latest_documentation()
      File "/usr/local/lib/python2.7/dist-packages/syncthing/interface.py", line 42, in get_latest_documentation
        os.makedirs(cache_folder)
      File "/usr/lib/python2.7/os.py", line 157, in makedirs
        mkdir(name, mode)
    OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/syncthing/docs'
    

    Why it needs to download documentation?

    opened by techtonik 2
  • No examples or API documentation provided

    No examples or API documentation provided

    As I want to integrate syncthing API reading into collectd for data monitoring I need to specify the host/port etcetera. In the master branch only a simple test is provided.

    Could you add some stand-alone examples of using the library?

    opened by xor-gate 2
  • pip install misses modules dependency

    pip install misses modules dependency

    Tried to install from pip and before syncthing would install I needed to install: module requests module bunch

    Please add these dependencies to your pip install metadata.

    Running under ArchLinux (rolling distro).

    opened by xor-gate 2
  • Update last seen id after yielding the whole batch

    Update last seen id after yielding the whole batch

    Hello!

    After further investigation I found out that it's very handy to know if an event comes from the very first batch. Such events must be ignored because they are historical data, clients usually need only newer events.

    In order to achieve it I moved the assignment of the _last_seen_id after yielding the whole batch and exposed it as a property. Now it's possible to use the same approach as the official gui does: https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/eventService.js#L22

    Thank you!

    UPD: Catch one more timeout exception

    opened by zhulik 1
  • Retry long polling on any timeout

    Retry long polling on any timeout

    Other changes:

    • Bump deps, declare 3.8 support
    • Always verify requests to avoid warnings when syncthing server uses valid SSL certificate
    • Bump version to 2.4

    If everything is ok, please, draft a new release, I'm about to use this package to develop a syncthing integration for https://github.com/home-assistant/core, and it would be awesome if the changes would be available on pypi asap

    opened by zhulik 1
  • Don't call resp.text

    Don't call resp.text

    Currently, using system.pause() and system.resume() causes a TypeError, since resp.text is either str (python3) or unicode (python2). Not trying to call resp.text avoids this.

    opened by classicsc 1
  • deployment issue on multiple devices

    deployment issue on multiple devices

    I'm running this script on multiple devices, and I wish to expand more in the future. What's the best strategy to configure API_KEY to make sure it's not relying on manual inputs one by one?

    opened by immartian 1
  • Fails with Python 3.9?

    Fails with Python 3.9?

    > pip3 install syncthing
    Collecting syncthing
      Downloading syncthing-2.4.2.tar.gz (12 kB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
        Preparing wheel metadata ... error
        ERROR: Command errored out with exit status 1:
         command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/tmpr7rltjfk
             cwd: /private/var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/pip-install-8goti_9c/syncthing
        Complete output (16 lines):
        Traceback (most recent call last):
          File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
            main()
          File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
            return hook(metadata_directory, config_settings)
          File "/private/var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/pip-build-env-52j602e6/overlay/lib/python3.9/site-packages/poetry/core/masonry/api.py", line 35, in prepare_metadata_for_build_wheel
            builder = WheelBuilder(poetry)
          File "/private/var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/pip-build-env-52j602e6/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 46, in __init__
            super(WheelBuilder, self).__init__(poetry, executable=executable)
          File "/private/var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/pip-build-env-52j602e6/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/builder.py", line 82, in __init__
            self._module = Module(
          File "/private/var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/pip-build-env-52j602e6/overlay/lib/python3.9/site-packages/poetry/core/masonry/utils/module.py", line 58, in __init__
            raise ModuleOrPackageNotFound(
        poetry.core.masonry.utils.module.ModuleOrPackageNotFound: No file/folder found for package python-syncthing
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/x5/fhclz7wd19168qv2gp61fpm40000gn/T/tmpr7rltjfk Check the logs for full command output.
    
    opened by pedrojvaz 1
  • `poetry add syncthing` is failing

    `poetry add syncthing` is failing

    Hello, thank you for making python syncthing! I'm trying it out , but running into the following error with doing poetry add syncthing. You should be able to try it out at https://repl.it/repls/EntirePaleSystemresource#main.py (be sure to press the PLAY button!).

    Have you encountered this before? Any idea how to get around it?

    --> python3 -m poetry add syncthing
    Using version ^2.4.2 for syncthing
    
    Updating dependencies
    Resolving dependencies...
    
    Writing lock file
    
    
    Package operations: 3 installs, 3 updates, 0 removals
    
      - Updating idna (2.9 -> 2.10)
      - Installing pytzdata (2020.1)
      - Updating urllib3 (1.25.9 -> 1.25.10)
      - Installing pendulum (2.1.2)
      - Updating yarl (1.4.2 -> 1.5.1)
      - Installing syncthing (2.4.2)
    
    [EnvCommandError]
    Command ['/opt/virtualenvs/python3/bin/pip', 'install', '--no-deps', 'syncthing==2.4.2'] errored with the following return code 1, and output: 
    Collecting syncthing==2.4.2
      Downloading syncthing-2.4.2.tar.gz (12 kB)
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
        Preparing wheel metadata: started
        Preparing wheel metadata: finished with status 'error'
        ERROR: Command errored out with exit status 1:
         command: /opt/virtualenvs/python3/bin/python3 /opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpq_a01jr9
             cwd: /tmp/pip-install-a4jmpbst/syncthing
        Complete output (16 lines):
        Traceback (most recent call last):
          File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
            main()
          File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
            return hook(metadata_directory, config_settings)
          File "/tmp/pip-build-env-7j243us7/overlay/lib/python3.8/site-packages/poetry/masonry/api.py", line 39, in prepare_metadata_for_build_wheel
            builder = WheelBuilder(poetry, SystemEnv(Path(sys.prefix)), NullIO())
          File "/tmp/pip-build-env-7j243us7/overlay/lib/python3.8/site-packages/poetry/masonry/builders/wheel.py", line 44, in __init__
            super(WheelBuilder, self).__init__(poetry, env, io)
          File "/tmp/pip-build-env-7j243us7/overlay/lib/python3.8/site-packages/poetry/masonry/builders/builder.py", line 65, in __init__
            self._module = Module(
          File "/tmp/pip-build-env-7j243us7/overlay/lib/python3.8/site-packages/poetry/masonry/utils/module.py", line 58, in __init__
            raise ModuleOrPackageNotFound(
        poetry.masonry.utils.module.ModuleOrPackageNotFound: No file/folder found for package python-syncthing
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /opt/virtualenvs/python3/bin/python3 /opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpq_a01jr9 Check the logs for full command output.
    WARNING: You are using pip version 20.1.1; however, version 20.2.2 is available.
    You should consider upgrading via the '/opt/virtualenvs/python3/bin/python3 -m pip install --upgrade pip' command.
    
    exit status 1
    
    
    opened by savil 2
  • Strange top level import issue

    Strange top level import issue

    Python 2.7.13 syncthing 2.3.1

    I have no idea why the interpreter is hitting line 41, but it is:

    (syncthing) jason@host:~$ python
    Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
    [GCC 6.3.0 20170516] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from syncthing import Syncthing
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/jason/venv/syncthing/local/lib/python2.7/site-packages/syncthing/__init__.py", line 41
        raise SyncthingError(msg) from exc
                                     ^
    SyntaxError: invalid syntax
    >>> from syncthing import Syncthing
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name Syncthing
    

    Full import:

    (syncthing) jason@host:~$ python
    Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
    [GCC 6.3.0 20170516] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import syncthing
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/jason/venv/syncthing/local/lib/python2.7/site-packages/syncthing/__init__.py", line 41
        raise SyncthingError(msg) from exc
                                     ^
    SyntaxError: invalid syntax
    >>> import syncthing
    >>> s = syncthing.Syncthing()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'Syncthing'
    >>> 
    
    opened by lingfish 4
Owner
Blake VandeMerwe
Blake VandeMerwe
A Python Library to interface with Flickr REST API, OAuth & JSON Responses

Python-Flickr Python-Flickr is A Python library to interface with Flickr REST API & OAuth Features Photo Uploading Retrieve user information Common Fl

Mike Helmick 40 Sep 25, 2021
A Python Library to interface with Tumblr v2 REST API & OAuth

Tumblpy Tumblpy is a Python library to help interface with Tumblr v2 REST API & OAuth Features Retrieve user information and blog information Common T

Mike Helmick 125 Jun 20, 2022
Python bindings for Alexa Web Information Service (AWIS) API

Attention! This package is no longer maintained. See this ticket for more info. Wraps Alexa Web Information Service. Usage Making UrlInfo requests: ap

Atamert Ölçgen 51 Feb 12, 2022
Python bindings for ArrayFire: A general purpose GPU library.

ArrayFire Python Bindings ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific

ArrayFire 402 Dec 20, 2022
Python bindings for BigML.io

BigML Python Bindings BigML makes machine learning easy by taking care of the details required to add data-driven decisions and predictive power to yo

BigML Inc, Machine Learning made easy 271 Dec 27, 2022
Disqus API bindings for Python

disqus-python Let's start with installing the API: pip install disqus-python Use the API by instantiating it, and then calling the method through dott

DISQUS 163 Oct 14, 2022
Python bindings for LibreTranslate

Python bindings for LibreTranslate

Argos Open Tech 42 Jan 3, 2023
pylunasvg - Python bindings for lunasvg

pylunasvg - Python bindings for lunasvg Pylunasvg is a simple wrapper around lunasvg that uses pybind11 to create python bindings. All public API of t

Eren 6 Jan 5, 2023
Python library for interacting with the Wunderlist 2 REST API

Overview Wunderpy2 is a thin Python library for accessing the official Wunderlist 2 API. What does a thin library mean here? Only the bare minimum of

mieubrisse 24 Dec 29, 2020
A very simple Salesforce.com REST API client for Python

Simple Salesforce Simple Salesforce is a basic Salesforce.com REST API client built for Python 3.5, 3.6, 3.7 and 3.8. The goal is to provide a very lo

simple salesforce 1.4k Dec 29, 2022
📦 Opensource Python wrapper for Hiven's REST and WebSocket API

hiven.py ?? Opensource Python wrapper for Hiven's REST and WebSocket API Installation pip install -U hiven.py Usage hiven.py is currently under devel

Kevin Thomas 3 Sep 3, 2021
NiceHash Python Library and Command Line Rest API

NiceHash Python Library and Command Line Rest API Requirements / Modules pip install requests Required data and where to get it Following data is nee

Ashlin Darius Govindasamy 2 Jan 2, 2022
NiceHash Python Library and Command Line Rest API

NiceHash Python Library and Command Line Rest API Requirements / Modules pip install requests Required data and where to get it Following data is nee

Ashlin Darius Govindasamy 2 Jan 2, 2022
An unofficial Python wrapper for the 'Binance exchange REST API'

Welcome to binex_f v0.1.0 many interfaces are heavily used by myself in product environment, the websocket is reliable (re)connected. Latest version:

DeepLn 2 Jan 5, 2022
TM1py is a Python package that wraps the TM1 REST API in a simple to use library.

By wrapping the IBM Planning Analytics (TM1) REST API in a concise Python framework, TM1py facilitates Python developments for TM1. Interacting with T

Cubewise CODE 147 Dec 15, 2022
pyDuinoCoin is a simple python integration for the DuinoCoin REST API, that allows developers to communicate with DuinoCoin Master Server

PyDuinoCoin PyDuinoCoin is a simple python integration for the DuinoCoin REST API, that allows developers to communicate with DuinoCoin Main Server. I

BackrndSource 6 Jul 14, 2022
Python library wrapping and enhancing the Invenio RDM REST API.

Iridium The metal Iridium is used to refine and enhance metal alloys. Similarly, this package provides an enhanced coating around the Invenio RDM APIs

Materials Data Science and Informatics 2 Mar 29, 2022
HTTP Calls to Amazon Web Services Rest API for IoT Core Shadow Actions 💻🌐💡

aws-iot-shadow-rest-api HTTP Calls to Amazon Web Services Rest API for IoT Core Shadow Actions ?? ?? ?? This simple script implements the following aw

AIIIXIII 3 Jun 6, 2022
Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks.

JackrabbitRelay Jackrabbit Relay is an API endpoint for stock, forex and cryptocurrency exchanges that accept REST webhooks. Disclaimer Please note RA

Rose Heart 23 Jan 4, 2023