Package: python-synology
Installation[sudo]pipinstallpython-synologyUsageYou can import the module assynology_dsm.ConstructorSynologyDSM(dsm_ip,dsm_port,username,password,use_https=False,verify_ssl=False,timeout=None,device_token=None,debugmode=False,)device_tokenshould be added when using a two-step authentication account, otherwise DSM will ask to login with a One Time Password (OTP) and requests will fail (see the login section for more details).Defaulttimeoutis 10 seconds.LoginThe library automatically login at first request, but you better use thelogin()function separately to authenticate.It will return a boolean if it successed or faild to authenticate to DSM.If your account need a two-step authentication (2SA),login()will raiseSynologyDSMLogin2SARequiredException.
Call the function again with a One Time Password (OTP) as parameter, likelogin("123456")(better to be a string to handle first zero).
Store thedevice_tokenproperty so that you do not need to reconnect with password the next time you open a newSynologyDSMsession.Code exempleEvery API has anupdate()function that is needed to get the first data, then the data is cached and updated at the nextupdate()call.TheSynologyDSMclass can alsoupdate()all APIs at once.fromsynology_dsmimportSynologyDSMprint("Creating Valid API")api=SynologyDSM("<IP/DNS>","<port>","<username>","<password>")print("=== Information ===")api.information.update()print("Model:           "+str(api.information.model))print("RAM:             "+str(api.information.ram)+" MB")print("Serial number:   "+str(api.information.serial))print("Temperature:     "+str(api.information.temperature)+" °C")print("Temp. warning:   "+str(api.information.temperature_warn))print("Uptime:          "+str(api.information.uptime))print("Full DSM version:"+str(api.information.version_string))print("--")print("=== Utilisation ===")api.utilisation.update()print("CPU Load:        "+str(api.utilisation.cpu_total_load)+" %")print("Memory Use:      "+str(api.utilisation.memory_real_usage)+" %")print("Net Up:          "+str(api.utilisation.network_up()))print("Net Down:        "+str(api.utilisation.network_down()))print("--")print("=== Storage ===")api.storage.update()forvolume_idinapi.storage.volumes_ids:print("ID:          "+str(volume_id))print("Status:      "+str(api.storage.volume_status(volume_id)))print("% Used:      "+str(api.storage.volume_percentage_used(volume_id))+" %")print("--")fordisk_idinapi.storage.disks_ids:print("ID:          "+str(disk_id))print("Name:        "+str(api.storage.disk_name(disk_id)))print("S-Status:    "+str(api.storage.disk_smart_status(disk_id)))print("Status:      "+str(api.storage.disk_status(disk_id)))print("Temp:        "+str(api.storage.disk_temp(disk_id)))print("--")print("=== Shared Folders ===")api.share.update()forshare_uuidinapi.share.shares_uuids:print("Share name:        "+str(api.share.share_name(share_uuid)))print("Share path:        "+str(api.share.share_path(share_uuid)))print("Space used:        "+str(api.share.share_size(share_uuid,human_readable=True)))print("Recycle Bin Enabled: "+str(api.share.share_recycle_bin(share_uuid)))print("--")Download Station usagefromsynology_dsmimportSynologyDSMapi=SynologyDSM("<IP/DNS>","<port>","<username>","<password>")if"SYNO.DownloadStation.Info"inapi.apis:api.download_station.get_info()api.download_station.get_config()# The download list will be updated after each of the following functions:# You should have the right on the (default) directory that the download will be saved, or you will get a 403 or 406 errorapi.download_station.create("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")api.download_station.pause("dbid_1")# Like the other function, you can eather pass a str or a listapi.download_station.resume(["dbid_1","dbid_2"])api.download_station.delete("dbid_3")# Manual updateapi.download_station.update()Surveillance Station usagefromsynology_dsmimportSynologyDSMapi=SynologyDSM("<IP/DNS>","<port>","<username>","<password>")surveillance=api.surveillance_stationsurveillance.update()# First update is required# Returns a list of cached cameras availablecameras=surveillance.get_all_cameras()# Assuming there's at least one camera, get the first camera_idcamera_id=cameras[0].camera_id# Returns cached camera object by camera_idcamera=surveillance.get_camera(camera_id)# Returns cached motion detection enabledmotion_setting=camera.is_motion_detection_enabled# Return bytes of camera imagesurveillance.get_camera_image(camera_id)# Updates all cameras/motion settings and cahce themsurveillance.update()# Gets Home Mode statushome_mode_status=surveillance.get_home_mode_status()# Sets home mode - true is on, false is offsurveillance.set_home_mode(True)System usagefromsynology_dsmimportSynologyDSMapi=SynologyDSM("<IP/DNS>","<port>","<username>","<password>")system=api.system# Reboot NASsystem.reboot()# Shutdown NASsystem.shutdown()# Manual update system informationsystem.update()# Get CPU informationsystem.cpu_clock_speedsystem.cpu_coressystem.cpu_familysystem.cpu_series# Get NTP settingssystem.enabled_ntpsystem.ntp_server# Get system informationsystem.firmware_versystem.modelsystem.ram_sizesystem.serialsystem.sys_tempsystem.timesystem.time_zonesystem.time_zone_descsystem.up_time# Get list of all connected USB devicessystem.usb_devUpgrade usagefromsynology_dsmimportSynologyDSMapi=SynologyDSM("<IP/DNS>","<port>","<username>","<password>")upgrade=api.upgrade# Manual update upgrade informationupgrade.update()# check if DSM update is availableifupgrade.update_available:dosomething...Credits / Special Thankshttps://github.com/florianeinfalthttps://github.com/tchellomellohttps://github.com/Quentame(Multiple API addition & tests)https://github.com/aaska(DSM 5 tests)https://github.com/chemelli74(2SA tests)https://github.com/snjoetw(Surveillance Station library)https://github.com/shenxn(Surveillance Station tests)https://github.com/Gestas(Shared Folders)Found Synology API “documentation” on this repo :https://github.com/kwent/syno/tree/master/definitionsOfficial referencesCalendar API documentation (2015-2019)Download Station API documentation (2012-2014)File Station API documentation (2013-2019)Surveillance Station API documentation (2012-2020)Virtual Machine Manager API documentation (2015-2019)