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

79 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 18:41 +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. ', 

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(default=None, description='Current screen resolution.') 

57 ) 

58 touch_support: Optional[TouchSupport] = None 

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

60 architecture: Optional[StrictInt] = Field( 

61 default=None, 

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

63 ) 

64 cookies_enabled: Optional[StrictBool] = Field( 

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

66 ) 

67 hardware_concurrency: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field( 

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

69 ) 

70 date_time_locale: Optional[StrictStr] = Field( 

71 default=None, 

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

73 ) 

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

75 color_depth: Optional[StrictInt] = Field( 

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

77 ) 

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

79 session_storage: Optional[StrictBool] = Field( 

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

81 ) 

82 local_storage: Optional[StrictBool] = Field( 

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

84 ) 

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

86 default=None, 

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

88 ) 

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

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

91 ) 

92 indexed_db: Optional[StrictBool] = Field( 

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

94 ) 

95 math: Optional[StrictStr] = Field( 

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

97 ) 

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

99 'font_preferences', 

100 'emoji', 

101 'fonts', 

102 'device_memory', 

103 'timezone', 

104 'canvas', 

105 'languages', 

106 'webgl_extensions', 

107 'webgl_basics', 

108 'screen_resolution', 

109 'touch_support', 

110 'oscpu', 

111 'architecture', 

112 'cookies_enabled', 

113 'hardware_concurrency', 

114 'date_time_locale', 

115 'vendor', 

116 'color_depth', 

117 'platform', 

118 'session_storage', 

119 'local_storage', 

120 'audio', 

121 'plugins', 

122 'indexed_db', 

123 'math', 

124 ] 

125 

126 model_config = ConfigDict( 

127 populate_by_name=True, 

128 validate_assignment=True, 

129 protected_namespaces=(), 

130 ) 

131 

132 def to_str(self) -> str: 

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

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

135 

136 def to_json(self) -> str: 

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

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

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

140 

141 @classmethod 

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

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

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

145 

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

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

148 

149 This has the following differences from calling pydantic's 

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

151 

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

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

154 are ignored. 

155 """ 

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

157 

158 _dict = self.model_dump( 

159 by_alias=True, 

160 exclude=excluded_fields, 

161 exclude_none=True, 

162 ) 

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

164 if self.font_preferences: 

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

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

167 if self.emoji: 

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

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

170 if self.canvas: 

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

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

173 if self.webgl_extensions: 

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

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

176 if self.webgl_basics: 

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

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

179 if self.touch_support: 

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

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

182 _items = [] 

183 if self.plugins: 

184 for _item_plugins in self.plugins: 

185 if _item_plugins: 

186 _items.append(_item_plugins.to_dict()) 

187 _dict['plugins'] = _items 

188 return _dict 

189 

190 @classmethod 

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

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

193 if obj is None: 

194 return None 

195 

196 if not isinstance(obj, dict): 

197 return cls.model_validate(obj) 

198 

199 _obj = cls.model_validate( 

200 { 

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

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

203 else None, 

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

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

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

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

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

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

210 else None, 

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

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

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

214 else None, 

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

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

217 else None, 

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

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

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

221 else None, 

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

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

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

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

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

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

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

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

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

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

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

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

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

235 else None, 

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

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

238 } 

239 ) 

240 return _obj