Usage¶
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
api_key | string | API key | Yes |
api_url | string | Url to connect to. Default is https://127.0.0.1:8384 | No |
Make a new instance of SyncthingClient with API key and Url.
>> from pysyncthing import SyncthingClient
>> client = SyncthingClient('XX6406JTI3NH673QRHOGU840PL8702', 'https://192.168.1.26:8384')
get_version()¶
returns current version
>> client.get_version()
Response:
{'arch': 'amd64',
'codename': 'Aluminium Ant',
'longVersion': 'syncthing v0.11.25 "Aluminium Ant" (go1.4.2 linux-amd64 default) mockbuild@build2.home.topdog-software.com 2015-10-01 13:56:48 UTC',
'os': 'linux',
'version': 'v0.11.25'}
get_connections()¶
Returns current connections
>> client.get_connections()
Response:
{'connections': {},
'total': {'address': '',
'at': '2015-11-10T09:47:04.702349573+02:00',
'clientVersion': '',
'inBytesTotal': 0,
'outBytesTotal': 0}}
get_config()¶
Returns current syncthing config
>> client.get_connections()
Response:
{'devices': [{'addresses': ['dynamic'],
'certName': '',
'compression': 'metadata',
'deviceID': 'KIQNIU2-FCDVMLH-UOHLLDI-7XYZRDU-TPEQSW4-B4W3YTF-LWUJP3N-6SMUFFK',
'introducer': False,
'name': 'standalone.home.topdog-software.com'}],
'folders': [{'autoNormalize': True,
'copiers': 0,
'devices': [{'deviceID': 'KIQNIU2-FCDVMLH-UOHLLDI-7XYZRDU-TPEQSW4-B4W3YTF-LWUJP3N-6SMUFFK'}],
'hashers': 0,
'id': 'ms-quarantine',
'ignoreDelete': False,
'ignorePerms': False,
'invalid': '',
'minDiskFreePct': 1,
'order': 'random',
'path': '/var/spool/MailScanner/quarantine',
'pullers': 0,
'readOnly': False,
'rescanIntervalS': 60,
'versioning': {'params': {}, 'type': ''}}],
'gui': {'address': '0.0.0.0:8384',
'apiKey': 'C1CrL0g-GZSD9galtsad6gl6pXOhk665',
'enabled': True,
'password': '',
'useTLS': True,
'user': ''},
'ignoredDevices': [],
'options': {'autoUpgradeIntervalH': 12,
'cacheIgnoredFiles': True,
'databaseBlockCacheMiB': 0,
'globalAnnounceEnabled': False,
'globalAnnounceServers': ['udp4://announce.syncthing.net:22026',
'udp6://announce-v6.syncthing.net:22026'],
'keepTemporariesH': 24,
'limitBandwidthInLan': False,
'listenAddress': ['0.0.0.0:1027'],
'localAnnounceEnabled': False,
'localAnnounceMCAddr': '[ff32::5222]:21026',
'localAnnouncePort': 21025,
'maxRecvKbps': 0,
'maxSendKbps': 0,
'minHomeDiskFreePct': 1,
'pingIdleTimeS': 60,
'pingTimeoutS': 30,
'progressUpdateIntervalS': 5,
'reconnectionIntervalS': 60,
'restartOnWakeup': True,
'startBrowser': False,
'symlinksEnabled': True,
'upnpEnabled': False,
'upnpLeaseMinutes': 60,
'upnpRenewalMinutes': 30,
'upnpTimeoutSeconds': 10,
'urAccepted': -1,
'urUniqueId': ''},
'version': 11}
get_insync()¶
Returns current insync condition
>> client.get_insync()
Response:
{'configInSync': True}
new_error()¶
Raises a new error with given message. Returns code 200 on success.
>> client.new_error('foo')
Response:
{'message': 'Completed successfully', 'code': 200}
clear_errors()¶
Clears previously raised errors. Returns code 200 on success.
>> client.clear_errors()
Response:
{'message': 'Completed successfully', 'code': 200}
new_config()¶
Uploads a new config to syncthing server.
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
config | Dict | New syncthing config | Yes |
cfg = {}
>> client.new_config(cfg)
Response:
{'message': 'Completed successfully', 'code': 200}
reset()¶
This means renaming all repository directories to temporary, unique names, destroying all indexes and restarting.
This should probably not be used during normal operations...
>> client.reset()
Response:
{'ok': 'resetting database'}
upgrade()¶
Perform an upgrade and restart if new version exists. Does nothing if current version is latest.
>> client.upgrade()
Response:
{'message': 'Completed successfully', 'code': 200}
get_status()¶
Returns current status
>> client.get_status()
Response:
{'alloc': 8319640,
'cpuPercent': 0.0399951236269495,
'goroutines': 34,
'myID': 'KIQNIU2-FCDVMLH-UOHLLDI-7XYZRDU-TPEQSW4-B4W3YTF-LWUJP3N-6SMUFFK',
'pathSeparator': '/',
'sys': 16267512,
'tilde': '/var/spool/exim',
'uptime': 752}
browse_databse()¶
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | Name of a database | Yes |
level | int | Depth of a list. Default is 0 - maximum depth |
No |
prefix | string | Path to directory or subdirectory to start from | No |
Returns files in given folder
>> client.browse_databse('ms-quarantine')
Response:
{'phishingupdate': {'cache': {'2092': ['2015-08-06T16:08:26+02:00',
252661],
'2092.42': ['2015-08-08T09:10:49+02:00',
248535]},
'status': ['2015-08-08T09:10:49+02:00', 8]}}
get_completion()¶
Returns completion in percentage (0-100) for given device and folder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
device | string | device_id | Yes |
folder | string | folder name | Yes |
>> client.get_completion('6RBLNBN-6EIGPRG-ZLZR7XI-LDWUXSE-NYWEBLI-3DFE2AI-L2DP3JL-4R77ZAM', 'ms-quarantine')
Response:
{'completion': 100}
get_file()¶
Returns info for given file
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
file | string | file name | Yes |
>> client.get_file('phishingupdate')
Response:
{'availability': None,
'global': {'flags': '0',
'localVersion': 0,
'modified': '1970-01-01T02:00:00+02:00',
'name': '',
'numBlocks': 0,
'size': 0,
'version': []},
'local': {'flags': '0',
'localVersion': 0,
'modified': '1970-01-01T02:00:00+02:00',
'name': '',
'numBlocks': 0,
'size': 0,
'version': []}}
get_ignores()¶
Returns ignores for given folder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
>> client.get_ignores('ms-quarantine')
Response:
{'ignore': None, 'patterns': None}
new_ignores()¶
Sets new ignores for given folder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
ignores | object | ignore object like in get_ignores response |
Yes |
>> ignores = {'ignore': ['foo']}
>> client.new_ignores('ms-quarantine', ignores)
Response:
{'ignore': ['foo'], 'patterns': ['^foo$', '^.*/foo$', '^foo/.*$', '^.*/foo/.*$']}
need()¶
Returns files which are needed for this device.
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
>> client.get_need('ms-quarantine')
Response:
{'perpage': 65536, 'rest': [], 'queued': [], 'progress': [], 'total': 0, 'page': 1}
assign_priority()¶
Assigns top priority for a given file in a given folder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
file | string | filename | Yes |
>> client.assign_priority('ms-quarantine', '1Ze9NH-00057p-Vl')
Response:
{'perpage': 65536, 'rest': [], 'queued': [], 'progress': [], 'total': 0, 'page': 1}
scan()¶
Request an immediate rescan of a folder with a subfolder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
subfolder | string | subfolder name | No |
>> client.scan('ms-quarantine')
Response:
{'message': 'Completed successfully', 'code': 200}
get_folder_status()¶
Returns status for a given folder
Parameters
Name | Type | Description | Mandatory? |
---|---|---|---|
folder | string | folder | Yes |
>> client.get_folder_status('ms-quarantine')
Response:
{'globalBytes': 501460,
'globalDeleted': 0,
'globalFiles': 5,
'ignorePatterns': True,
'inSyncBytes': 501460,
'inSyncFiles': 5,
'invalid': '',
'localBytes': 501460,
'localDeleted': 0,
'localFiles': 5,
'needBytes': 0,
'needFiles': 0,
'state': 'idle',
'stateChanged': '2015-11-10T10:03:28.992782938+02:00',
'version': 6}
get_device_statistics()¶
Returns device statistics
>> client.get_device_statistics()
Response:
{'KIQNIU2-FCDVMLH-UOHLLDI-7XYZRDU-TPEQSW4-B4W3YTF-LWUJP3N-6SMUFFK': {'lastSeen': '1970-01-01T02:00:00+02:00'}}
get_folder_statistics()¶
Returns general statistics about folders.
>> client.get_folder_statistics()
Response:
{'ms-quarantine': {'lastFile': {'at': '0001-01-01T00:00:00Z',
'deleted': False,
'filename': ''}}}