Coverage for fingerprint_server_sdk/models/raw_device_attributes.py: 70%

87 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-08-05 16:08 +0000

1""" 

2Server API 

3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. 

4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. 

5The API also supports collection of Automation Intelligence for requests to your server in edge, pre-origin, or middleware contexts. 

6 

7The version of the OpenAPI document: 4 

8Contact: support@fingerprint.com 

9Generated by OpenAPI Generator (https://openapi-generator.tech) 

10 

11Do not edit the class manually. 

12""" # noqa: E501 

13 

14from __future__ import annotations 

15 

16import json 

17import pprint 

18import re # noqa: F401 

19from typing import Annotated, Any, ClassVar, Optional, Union 

20 

21from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr 

22from typing_extensions import Self 

23 

24from fingerprint_server_sdk.models.canvas import Canvas 

25from fingerprint_server_sdk.models.emoji import Emoji 

26from fingerprint_server_sdk.models.font_preferences import FontPreferences 

27from fingerprint_server_sdk.models.plugins_inner import PluginsInner 

28from fingerprint_server_sdk.models.touch_support import TouchSupport 

29from fingerprint_server_sdk.models.web_gl_basics import WebGlBasics 

30from fingerprint_server_sdk.models.web_gl_extensions import WebGlExtensions 

31 

32 

33class RawDeviceAttributes(BaseModel): 

34 """ 

35 A curated subset of raw browser/device attributes that the API surface exposes. Each property contains a value or object with the data for the collected signal. 

36 """ 

37 

38 font_preferences: Optional[FontPreferences] = None 

39 emoji: Optional[Emoji] = None 

40 fonts: Optional[list[StrictStr]] = Field( 

41 default=None, description='List of fonts detected on the device.' 

42 ) 

43 device_memory: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field( 

44 default=None, 

45 description='Rounded amount of RAM in gigabytes. Available for browsers, Android, and iOS devices.', 

46 ) 

47 timezone: Optional[StrictStr] = Field( 

48 default=None, description='Timezone identifier detected on the client.' 

49 ) 

50 canvas: Optional[Canvas] = None 

51 languages: Optional[list[list[StrictStr]]] = Field( 

52 default=None, 

53 description='Navigator languages reported by the agent including fallbacks. Each inner array represents ordered language preferences reported by different APIs. Available for browsers, iOS, and Android devices. ', 

54 ) 

55 webgl_extensions: Optional[WebGlExtensions] = None 

56 webgl_basics: Optional[WebGlBasics] = None 

57 screen_resolution: Optional[Annotated[list[StrictInt], Field(min_length=2, max_length=2)]] = ( 

58 Field( 

59 default=None, 

60 description='Current screen resolution. Available for both browsers and iOS devices', 

61 ) 

62 ) 

63 touch_support: Optional[TouchSupport] = None 

64 oscpu: Optional[StrictStr] = Field(default=None, description='Navigator `oscpu` string.') 

65 architecture: Optional[StrictInt] = Field( 

66 default=None, 

67 description='Integer representing the CPU architecture exposed by the browser.', 

68 ) 

69 cookies_enabled: Optional[StrictBool] = Field( 

70 default=None, description='Whether the cookies are enabled in the browser.' 

71 ) 

72 hardware_concurrency: Optional[StrictInt] = Field( 

73 default=None, description='Number of logical CPU cores reported by the browser.' 

74 ) 

75 date_time_locale: Optional[StrictStr] = Field( 

76 default=None, 

77 description='Locale derived from the Intl.DateTimeFormat API. Negative values indicate known error states. The negative statuses can be: - "-1": A permanent status for browsers that don\'t support Intl API. - "-2": A permanent status for browsers that don\'t supportDateTimeFormat constructor. - "-3": A permanent status for browsers in which DateTimeFormat locale is undefined or null. ', 

78 ) 

79 vendor: Optional[StrictStr] = Field(default=None, description='Navigator vendor string.') 

80 color_depth: Optional[StrictInt] = Field( 

81 default=None, description='Screen color depth in bits.' 

82 ) 

83 platform: Optional[StrictStr] = Field(default=None, description='Navigator platform string.') 

84 session_storage: Optional[StrictBool] = Field( 

85 default=None, description='Whether sessionStorage is available.' 

86 ) 

87 local_storage: Optional[StrictBool] = Field( 

88 default=None, description='Whether localStorage is available.' 

89 ) 

90 audio: Optional[Union[StrictFloat, StrictInt]] = Field( 

91 default=None, 

92 description="AudioContext fingerprint or negative status when unavailable. The negative statuses can be: - -1: A permanent status for those browsers which are known to always suspend audio context - -2: A permanent status for browsers that don't support the signal - -3: A temporary status that means that an unexpected timeout has happened ", 

93 ) 

94 plugins: Optional[list[PluginsInner]] = Field( 

95 default=None, description='Browser plugins reported by `navigator.plugins`.' 

96 ) 

97 indexed_db: Optional[StrictBool] = Field( 

98 default=None, description='Whether IndexedDB is available.' 

99 ) 

100 math: Optional[StrictStr] = Field( 

101 default=None, description='Hash of Math APIs used for entropy collection.' 

102 ) 

103 device_model: Optional[StrictStr] = Field( 

104 default=None, 

105 description='Device model string. Available only for Android and iOS devices.', 

106 ) 

107 device_manufacturer: Optional[StrictStr] = Field( 

108 default=None, 

109 description='Device manufacturer string. Available only for Android and iOS devices.', 

110 ) 

111 font_hash: Optional[StrictStr] = Field( 

112 default=None, description='Unique identifier for the user’s installed fonts.' 

113 ) 

114 timezone_offset: Optional[StrictStr] = Field( 

115 default=None, 

116 description='UTC offset in "±HH:MM" format derived from the detected IANA timezone.', 

117 ) 

118 battery_level: Optional[Annotated[int, Field(le=100, strict=True, ge=0)]] = Field( 

119 default=None, 

120 description='Battery charge level as a percentage (0-100). Available for Android, iOS, and web devices. On web, only available in Chromium-based browsers.', 

121 ) 

122 battery_charging: Optional[StrictBool] = Field( 

123 default=None, 

124 description='When `true`, the device is currently charging. Available only for web devices on Chromium-based browsers.', 

125 ) 

126 battery_low_power_mode: Optional[StrictBool] = Field( 

127 default=None, 

128 description="Whether the device's low power mode is enabled. Available only for Android and iOS devices.", 

129 ) 

130 keyboard_layout_hash: Optional[StrictStr] = Field( 

131 default=None, description="Unique identifier for the user's keyboard layout." 

132 ) 

133 __properties: ClassVar[list[str]] = [ 

134 'font_preferences', 

135 'emoji', 

136 'fonts', 

137 'device_memory', 

138 'timezone', 

139 'canvas', 

140 'languages', 

141 'webgl_extensions', 

142 'webgl_basics', 

143 'screen_resolution', 

144 'touch_support', 

145 'oscpu', 

146 'architecture', 

147 'cookies_enabled', 

148 'hardware_concurrency', 

149 'date_time_locale', 

150 'vendor', 

151 'color_depth', 

152 'platform', 

153 'session_storage', 

154 'local_storage', 

155 'audio', 

156 'plugins', 

157 'indexed_db', 

158 'math', 

159 'device_model', 

160 'device_manufacturer', 

161 'font_hash', 

162 'timezone_offset', 

163 'battery_level', 

164 'battery_charging', 

165 'battery_low_power_mode', 

166 'keyboard_layout_hash', 

167 ] 

168 

169 model_config = ConfigDict( 

170 populate_by_name=True, 

171 validate_assignment=True, 

172 protected_namespaces=(), 

173 ) 

174 

175 def to_str(self) -> str: 

176 """Returns the string representation of the model using alias""" 

177 return pprint.pformat(self.model_dump(by_alias=True)) 

178 

179 def to_json(self) -> str: 

180 """Returns the JSON representation of the model using alias""" 

181 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

182 return json.dumps(self.to_dict()) 

183 

184 @classmethod 

185 def from_json(cls, json_str: str) -> Optional[Self]: 

186 """Create an instance of RawDeviceAttributes from a JSON string""" 

187 return cls.from_dict(json.loads(json_str)) 

188 

189 def to_dict(self) -> dict[str, Any]: 

190 """Return the dictionary representation of the model using alias. 

191 

192 This has the following differences from calling pydantic's 

193 `self.model_dump(by_alias=True)`: 

194 

195 * `None` is only added to the output dict for nullable fields that 

196 were set at model initialization. Other fields with value `None` 

197 are ignored. 

198 """ 

199 excluded_fields: set[str] = set([]) 

200 

201 _dict = self.model_dump( 

202 by_alias=True, 

203 exclude=excluded_fields, 

204 exclude_none=True, 

205 ) 

206 # override the default output from pydantic by calling `to_dict()` of font_preferences 

207 if self.font_preferences: 

208 _dict['font_preferences'] = self.font_preferences.to_dict() 

209 # override the default output from pydantic by calling `to_dict()` of emoji 

210 if self.emoji: 

211 _dict['emoji'] = self.emoji.to_dict() 

212 # override the default output from pydantic by calling `to_dict()` of canvas 

213 if self.canvas: 

214 _dict['canvas'] = self.canvas.to_dict() 

215 # override the default output from pydantic by calling `to_dict()` of webgl_extensions 

216 if self.webgl_extensions: 

217 _dict['webgl_extensions'] = self.webgl_extensions.to_dict() 

218 # override the default output from pydantic by calling `to_dict()` of webgl_basics 

219 if self.webgl_basics: 

220 _dict['webgl_basics'] = self.webgl_basics.to_dict() 

221 # override the default output from pydantic by calling `to_dict()` of touch_support 

222 if self.touch_support: 

223 _dict['touch_support'] = self.touch_support.to_dict() 

224 # override the default output from pydantic by calling `to_dict()` of each item in plugins (list) 

225 _items = [] 

226 if self.plugins: 

227 for _item_plugins in self.plugins: 

228 if _item_plugins: 

229 _items.append(_item_plugins.to_dict()) 

230 _dict['plugins'] = _items 

231 return _dict 

232 

233 @classmethod 

234 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

235 """Create an instance of RawDeviceAttributes from a dict""" 

236 if obj is None: 

237 return None 

238 

239 if not isinstance(obj, dict): 

240 return cls.model_validate(obj) 

241 

242 _obj = cls.model_validate( 

243 { 

244 'font_preferences': FontPreferences.from_dict(obj['font_preferences']) 

245 if obj.get('font_preferences') is not None 

246 else None, 

247 'emoji': Emoji.from_dict(obj['emoji']) if obj.get('emoji') is not None else None, 

248 'fonts': obj.get('fonts'), 

249 'device_memory': obj.get('device_memory'), 

250 'timezone': obj.get('timezone'), 

251 'canvas': Canvas.from_dict(obj['canvas']) 

252 if obj.get('canvas') is not None 

253 else None, 

254 'languages': obj.get('languages'), 

255 'webgl_extensions': WebGlExtensions.from_dict(obj['webgl_extensions']) 

256 if obj.get('webgl_extensions') is not None 

257 else None, 

258 'webgl_basics': WebGlBasics.from_dict(obj['webgl_basics']) 

259 if obj.get('webgl_basics') is not None 

260 else None, 

261 'screen_resolution': obj.get('screen_resolution'), 

262 'touch_support': TouchSupport.from_dict(obj['touch_support']) 

263 if obj.get('touch_support') is not None 

264 else None, 

265 'oscpu': obj.get('oscpu'), 

266 'architecture': obj.get('architecture'), 

267 'cookies_enabled': obj.get('cookies_enabled'), 

268 'hardware_concurrency': obj.get('hardware_concurrency'), 

269 'date_time_locale': obj.get('date_time_locale'), 

270 'vendor': obj.get('vendor'), 

271 'color_depth': obj.get('color_depth'), 

272 'platform': obj.get('platform'), 

273 'session_storage': obj.get('session_storage'), 

274 'local_storage': obj.get('local_storage'), 

275 'audio': obj.get('audio'), 

276 'plugins': [PluginsInner.from_dict(_item) for _item in obj['plugins']] 

277 if obj.get('plugins') is not None 

278 else None, 

279 'indexed_db': obj.get('indexed_db'), 

280 'math': obj.get('math'), 

281 'device_model': obj.get('device_model'), 

282 'device_manufacturer': obj.get('device_manufacturer'), 

283 'font_hash': obj.get('font_hash'), 

284 'timezone_offset': obj.get('timezone_offset'), 

285 'battery_level': obj.get('battery_level'), 

286 'battery_charging': obj.get('battery_charging'), 

287 'battery_low_power_mode': obj.get('battery_low_power_mode'), 

288 'keyboard_layout_hash': obj.get('keyboard_layout_hash'), 

289 } 

290 ) 

291 return _obj