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

83 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-15 09:18 +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. 

5 

6The version of the OpenAPI document: 4 

7Contact: support@fingerprint.com 

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

9 

10Do not edit the class manually. 

11""" # noqa: E501 

12 

13from __future__ import annotations 

14 

15import json 

16import pprint 

17import re # noqa: F401 

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

19 

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

21from typing_extensions import Self 

22 

23from fingerprint_server_sdk.models.canvas import Canvas 

24from fingerprint_server_sdk.models.emoji import Emoji 

25from fingerprint_server_sdk.models.font_preferences import FontPreferences 

26from fingerprint_server_sdk.models.plugins_inner import PluginsInner 

27from fingerprint_server_sdk.models.touch_support import TouchSupport 

28from fingerprint_server_sdk.models.web_gl_basics import WebGlBasics 

29from fingerprint_server_sdk.models.web_gl_extensions import WebGlExtensions 

30 

31 

32class RawDeviceAttributes(BaseModel): 

33 """ 

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

35 """ 

36 

37 font_preferences: Optional[FontPreferences] = None 

38 emoji: Optional[Emoji] = None 

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

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

41 ) 

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

43 default=None, description='Rounded amount of RAM (in gigabytes) reported by the browser.' 

44 ) 

45 timezone: Optional[StrictStr] = Field( 

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

47 ) 

48 canvas: Optional[Canvas] = None 

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

50 default=None, 

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

52 ) 

53 webgl_extensions: Optional[WebGlExtensions] = None 

54 webgl_basics: Optional[WebGlBasics] = None 

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

56 Field( 

57 default=None, 

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

59 ) 

60 ) 

61 touch_support: Optional[TouchSupport] = None 

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

63 architecture: Optional[StrictInt] = Field( 

64 default=None, 

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

66 ) 

67 cookies_enabled: Optional[StrictBool] = Field( 

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

69 ) 

70 hardware_concurrency: Optional[StrictInt] = Field( 

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

72 ) 

73 date_time_locale: Optional[StrictStr] = Field( 

74 default=None, 

75 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. ', 

76 ) 

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

78 color_depth: Optional[StrictInt] = Field( 

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

80 ) 

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

82 session_storage: Optional[StrictBool] = Field( 

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

84 ) 

85 local_storage: Optional[StrictBool] = Field( 

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

87 ) 

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

89 default=None, 

90 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 ", 

91 ) 

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

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

94 ) 

95 indexed_db: Optional[StrictBool] = Field( 

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

97 ) 

98 math: Optional[StrictStr] = Field( 

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

100 ) 

101 device_model: Optional[StrictStr] = Field( 

102 default=None, 

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

104 ) 

105 device_manufacturer: Optional[StrictStr] = Field( 

106 default=None, 

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

108 ) 

109 font_hash: Optional[StrictStr] = Field( 

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

111 ) 

112 timezone_offset: Optional[StrictStr] = Field( 

113 default=None, 

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

115 ) 

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

117 'font_preferences', 

118 'emoji', 

119 'fonts', 

120 'device_memory', 

121 'timezone', 

122 'canvas', 

123 'languages', 

124 'webgl_extensions', 

125 'webgl_basics', 

126 'screen_resolution', 

127 'touch_support', 

128 'oscpu', 

129 'architecture', 

130 'cookies_enabled', 

131 'hardware_concurrency', 

132 'date_time_locale', 

133 'vendor', 

134 'color_depth', 

135 'platform', 

136 'session_storage', 

137 'local_storage', 

138 'audio', 

139 'plugins', 

140 'indexed_db', 

141 'math', 

142 'device_model', 

143 'device_manufacturer', 

144 'font_hash', 

145 'timezone_offset', 

146 ] 

147 

148 model_config = ConfigDict( 

149 populate_by_name=True, 

150 validate_assignment=True, 

151 protected_namespaces=(), 

152 ) 

153 

154 def to_str(self) -> str: 

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

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

157 

158 def to_json(self) -> str: 

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

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

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

162 

163 @classmethod 

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

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

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

167 

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

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

170 

171 This has the following differences from calling pydantic's 

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

173 

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

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

176 are ignored. 

177 """ 

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

179 

180 _dict = self.model_dump( 

181 by_alias=True, 

182 exclude=excluded_fields, 

183 exclude_none=True, 

184 ) 

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

186 if self.font_preferences: 

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

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

189 if self.emoji: 

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

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

192 if self.canvas: 

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

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

195 if self.webgl_extensions: 

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

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

198 if self.webgl_basics: 

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

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

201 if self.touch_support: 

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

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

204 _items = [] 

205 if self.plugins: 

206 for _item_plugins in self.plugins: 

207 if _item_plugins: 

208 _items.append(_item_plugins.to_dict()) 

209 _dict['plugins'] = _items 

210 return _dict 

211 

212 @classmethod 

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

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

215 if obj is None: 

216 return None 

217 

218 if not isinstance(obj, dict): 

219 return cls.model_validate(obj) 

220 

221 _obj = cls.model_validate( 

222 { 

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

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

225 else None, 

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

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

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

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

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

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

232 else None, 

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

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

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

236 else None, 

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

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

239 else None, 

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

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

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

243 else None, 

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

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

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

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

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

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

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

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

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

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

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

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

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

257 else None, 

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

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

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

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

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

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

264 } 

265 ) 

266 return _obj