Coder Social home page Coder Social logo

python-syncthing's Introduction

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.

python-syncthing's People

Contributors

blakev avatar cbenhagen avatar classicsc avatar dependabot[bot] avatar fejese avatar kmarius avatar mdevey avatar pyhedgehog avatar ramwin avatar techtonik avatar zhulik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-syncthing's Issues

`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

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?

syncthing2 on pypi

There is a syncthing2 package on pypi referring to this repository.
But this seems to be the syncthing package here?
This is a bit confusing, please clarify.

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.

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.

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

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?

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?

Getting an error on install

This is the error I get when I try to install this:

(.venv) syncthing % pip install -r requirements.txt
Collecting syncthing (from -r requirements.txt (line 1))
Using cached syncthing-2.4.2.tar.gz (12 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error

× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [20 lines of output]
Traceback (most recent call last):
File "/home/**/Projects/home/syncthing/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/home/**/Projects/home/syncthing/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/**/Projects/home/syncthing/.venv/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-uk_kdgzt/overlay/lib/python3.11/site-packages/poetry/core/masonry/api.py", line 42, in prepare_metadata_for_build_wheel
builder = WheelBuilder(poetry)
^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-uk_kdgzt/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/wheel.py", line 61, in __init__
super().__init__(poetry, executable=executable)
File "/tmp/pip-build-env-uk_kdgzt/overlay/lib/python3.11/site-packages/poetry/core/masonry/builders/builder.py", line 85, in __init__
self._module = Module(
^^^^^^^
File "/tmp/pip-build-env-uk_kdgzt/overlay/lib/python3.11/site-packages/poetry/core/masonry/utils/module.py", line 69, in __init__
raise ModuleOrPackageNotFound(
poetry.core.masonry.utils.module.ModuleOrPackageNotFound: No file/folder found for package python-syncthing
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
pip install -r requirements.txt  6.42s user 0.32s system 75% cpu 8.911 total
% cat requirements.txt
syncthing
% ./.venv/bin/python --version
Python 3.11.4
% uname -a
Linux m 6.5.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 06 Sep 2023 21:01:01 +0000 x86_64 GNU/Linux

Thanks

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'
>>> 

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).

Scan Folder

Hi, first thanks for this library.
But scan a folder throw a exeption. The folder i want scan exist:

In [58]: sync.stats.folder()
Out[58]: 
{'UniShare': {'lastFile': {'at': '2016-02-17T14:28:06.901964811+01:00', …

Here is the exeption:

In [59]: sync.db.set.scan(folder="UniShare")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-59-1b1d8f30fc87> in <module>()
----> 1 sync.db.set.scan(folder="UniShare")

/tmp/venv/lib/python3.5/site-packages/syncthing/__init__.py in __call__(self, data_obj, **params)
     74 
     75         return C.iface.do_req(self.command.verb, self.command.endpoint, \
---> 76                                 data_obj, **params)
     77 
     78     def __str__(self):

/tmp/venv/lib/python3.5/site-packages/syncthing/__init__.py in do_req(self, verb, endpoint, data, **params)
    203     def do_req(self, verb, endpoint, data=None, **params):
    204         url = uparse.urljoin(self.host, endpoint)
--> 205         return self.__req(verb, url, data, params)
    206 
    207     def __req(self, verb, url, data=None, params=None):

/tmp/venv/lib/python3.5/site-packages/syncthing/__init__.py in __req(self, verb, url, data, params)
    254             else:
    255                 c = resp.content
--> 256                 if c.startswith('{') and c.endswith('}'):
    257                     return json.loads(c)
    258                 return c

TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Whatever, the folder get scanned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.