-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
1291 lines (1165 loc) · 53.1 KB
/
client.py
File metadata and controls
1291 lines (1165 loc) · 53.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import SyncClientWrapper
from ..generated_types.types.country import Country
from ..generated_types.types.both_identifier_types import BothIdentifierTypes
from ..generated_types.types.entities import Entities
from .types.profile_enum import ProfileEnum
from ..core.request_options import RequestOptions
from .types.resolution_response import ResolutionResponse
from ..core.pydantic_utilities import parse_obj_as
from ..shared_errors.errors.bad_request import BadRequest
from ..shared_errors.types.bad_request_response import BadRequestResponse
from ..shared_errors.errors.unauthorized import Unauthorized
from ..shared_errors.types.unauthorized_response import UnauthorizedResponse
from ..shared_errors.errors.method_not_allowed import MethodNotAllowed
from ..shared_errors.types.method_not_allowed_response import MethodNotAllowedResponse
from ..shared_errors.errors.not_acceptable import NotAcceptable
from ..shared_errors.types.not_acceptable_response import NotAcceptableResponse
from ..shared_errors.errors.rate_limit_exceeded import RateLimitExceeded
from ..shared_errors.types.rate_limit_response import RateLimitResponse
from ..shared_errors.errors.internal_server_error import InternalServerError
from ..shared_errors.types.internal_server_error_response import InternalServerErrorResponse
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from .types.resolution_body import ResolutionBody
from ..core.serialization import convert_and_respect_annotation_metadata
from .types.resolution_persisted_response import ResolutionPersistedResponse
from ..core.jsonable_encoder import jsonable_encoder
from .types.resolution_upload_body import ResolutionUploadBody
from .types.resolution_upload_response import ResolutionUploadResponse
from ..core.client_wrapper import AsyncClientWrapper
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class ResolutionClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper
def resolution(
self,
*,
limit: typing.Optional[int] = None,
offset: typing.Optional[int] = None,
name: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
address: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
city: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
state: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
country: typing.Optional[typing.Union[Country, typing.Sequence[Country]]] = None,
identifier: typing.Optional[typing.Union[BothIdentifierTypes, typing.Sequence[BothIdentifierTypes]]] = None,
date_of_birth: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
contact: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
type: typing.Optional[typing.Union[Entities, typing.Sequence[Entities]]] = None,
profile: typing.Optional[ProfileEnum] = None,
name_min_percentage: typing.Optional[int] = None,
name_min_tokens: typing.Optional[int] = None,
minimum_score_threshold: typing.Optional[int] = None,
search_fallback: typing.Optional[bool] = None,
cutoff_threshold: typing.Optional[int] = None,
candidate_pool_size: typing.Optional[int] = None,
skip_post_process: typing.Optional[bool] = None,
enable_llm_clean: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ResolutionResponse:
"""
The resolution endpoints allow users to search for matching entities against a provided list of attributes. The endpoint is similar to the search endpoint, except it's tuned to only return the best match so the client doesn't need to do as much or any post-processing work to filter down results.
Parameters
----------
limit : typing.Optional[int]
A limit on the number of objects to be returned with a range between 1 and 10 inclusive. Defaults to 10.
offset : typing.Optional[int]
Number of results to skip before returning response. Defaults to 0.
name : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity name
address : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity address. For optimal matching results, it's recommended to concatenate the full address string (street, city, state, postal code).
city : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity city that contains the provided city name.
state : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity state that contains the provided state name.
country : typing.Optional[typing.Union[Country, typing.Sequence[Country]]]
Entity country - must be ISO (3166) Trigram i.e., `USA`. See complete list [here](/sayari-library/ontology/enumerated-types#country)
identifier : typing.Optional[typing.Union[BothIdentifierTypes, typing.Sequence[BothIdentifierTypes]]]
Entity identifier. Can be from either the [Identifier Type](/sayari-library/ontology/enumerated-types#identifier-type) or [Weak Identifier Type](/sayari-library/ontology/enumerated-types#weak-identifier-type) enums.
date_of_birth : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity date of birth
contact : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity contact
type : typing.Optional[typing.Union[Entities, typing.Sequence[Entities]]]
[Entity type](/sayari-library/ontology/entities). If multiple values are passed for any field, the endpoint will match entities with ANY of the values.
profile : typing.Optional[ProfileEnum]
Specifies the search algorithm to use. `corporate` (default) is optimized for accurate entity attribute matching, ideal for business verification. `suppliers` is tailored for matching entities with trade data, suitable for supply chain use cases. `search` mimics /search/entity behavior, best for name-only matches.
name_min_percentage : typing.Optional[int]
Adding this param enables an alternative matching logic. It will set a minimum percentage of tokens needed to match with user input to be considered a "hit". Accepts integers from 0 to 100 inclusive.
name_min_tokens : typing.Optional[int]
Adding this param enables an alternative matching logic. It sets the minimum number of matching tokens the resolved hits need to have in common with the user input to be considered a "hit". Accepts non-negative integers.
minimum_score_threshold : typing.Optional[int]
Specifies the minimum score required to pass, which controls the strictness of the matching threshold. The default value is 77, and tuned for general use-case accuracy. Increase the value for stricter matching, reduce to loosen.
search_fallback : typing.Optional[bool]
Enables a name search fallback when either the corporate or supplier profiles fails to find a match. When invoked, the fallback will make a call similar to /search/entity on name only. By default set to false.
cutoff_threshold : typing.Optional[int]
Specifies the window of similar results returned in the match group. Increase for fewer multiple matches, decrease to open the aperture and allow for more matches. Default is .8
candidate_pool_size : typing.Optional[int]
Specifies the maximum number of entity candidates considered during search. Default is 50. Higher values increase match pool size but also increase latency.
skip_post_process : typing.Optional[bool]
Bypasses the post-processing setps and re-ranking. Useful for debugging. By default set to false, set to true to enable.
enable_llm_clean : typing.Optional[bool]
Whether to enable LLM-based data cleaning to remove noise and standardize entity attributes. Defaults to true if not supplied. Set to false to disable LLM cleaning.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionResponse
Examples
--------
from sayari import Sayari
client = Sayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client.resolution.resolution(
name="Thomas Bangalter",
address="8 AVENUE RACHEL",
country="FRA",
)
"""
_response = self._client_wrapper.httpx_client.request(
"v1/resolution",
method="GET",
params={
"limit": limit,
"offset": offset,
"name": name,
"address": address,
"city": city,
"state": state,
"country": country,
"identifier": identifier,
"date_of_birth": date_of_birth,
"contact": contact,
"type": type,
"profile": profile,
"name_min_percentage": name_min_percentage,
"name_min_tokens": name_min_tokens,
"minimum_score_threshold": minimum_score_threshold,
"search_fallback": search_fallback,
"cutoff_threshold": cutoff_threshold,
"candidate_pool_size": candidate_pool_size,
"skip_post_process": skip_post_process,
"enable_llm_clean": enable_llm_clean,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionResponse,
parse_obj_as(
type_=ResolutionResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 500:
raise InternalServerError(
typing.cast(
InternalServerErrorResponse,
parse_obj_as(
type_=InternalServerErrorResponse, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def resolution_post(
self,
*,
request: ResolutionBody,
limit: typing.Optional[int] = None,
offset: typing.Optional[int] = None,
enable_llm_clean: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ResolutionResponse:
"""
The resolution endpoints allow users to search for matching entities against a provided list of attributes. The endpoint is similar to the search endpoint, except it's tuned to only return the best match so the client doesn't need to do as much or any post-processing work to filter down results.
Parameters
----------
request : ResolutionBody
limit : typing.Optional[int]
A limit on the number of objects to be returned with a range between 1 and 10 inclusive. Defaults to 10.
offset : typing.Optional[int]
Number of results to skip before returning response. Defaults to 0.
enable_llm_clean : typing.Optional[bool]
Whether to enable LLM-based data cleaning to remove noise and standardize entity attributes. Defaults to true if not supplied. Set to false to disable LLM cleaning.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionResponse
Examples
--------
from sayari import Sayari
from sayari.resolution import ResolutionBody
client = Sayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client.resolution.resolution_post(
limit=1,
request=ResolutionBody(
name=["Thomas Bangalter"],
address=["8 AVENUE RACHEL"],
country=["FRA"],
),
)
"""
_response = self._client_wrapper.httpx_client.request(
"v1/resolution",
method="POST",
params={
"limit": limit,
"offset": offset,
"enable_llm_clean": enable_llm_clean,
},
json=convert_and_respect_annotation_metadata(object_=request, annotation=ResolutionBody, direction="write"),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionResponse,
parse_obj_as(
type_=ResolutionResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 500:
raise InternalServerError(
typing.cast(
InternalServerErrorResponse,
parse_obj_as(
type_=InternalServerErrorResponse, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def resolution_persisted(
self,
project_id: str,
*,
request: ResolutionBody,
limit: typing.Optional[int] = None,
offset: typing.Optional[int] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ResolutionPersistedResponse:
"""
<Warning>This endpoint is deprecated.</Warning> The persisted resolution endpoints allow users to search for matching entities against a provided list of attributes. The endpoint is similar to the resolution endpoint, except it also stores matched entities into user's project.
Parameters
----------
project_id : str
Unique identifier of the project
request : ResolutionBody
limit : typing.Optional[int]
A limit on the number of objects to be returned with a range between 1 and 10 inclusive. Defaults to 10.
offset : typing.Optional[int]
Number of results to skip before returning response. Defaults to 0.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionPersistedResponse
Examples
--------
from sayari import Sayari
from sayari.resolution import ResolutionBody
client = Sayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client.resolution.resolution_persisted(
project_id="V03eYM",
limit=1,
request=ResolutionBody(
name=["victoria beckham limited"],
),
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v1/resolution/persisted/{jsonable_encoder(project_id)}",
method="POST",
params={
"limit": limit,
"offset": offset,
},
json=convert_and_respect_annotation_metadata(object_=request, annotation=ResolutionBody, direction="write"),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionPersistedResponse,
parse_obj_as(
type_=ResolutionPersistedResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 500:
raise InternalServerError(
typing.cast(
InternalServerErrorResponse,
parse_obj_as(
type_=InternalServerErrorResponse, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def resolution_upload(
self, project_id: str, *, request: ResolutionUploadBody, request_options: typing.Optional[RequestOptions] = None
) -> ResolutionUploadResponse:
"""
<Warning>This endpoint is deprecated.</Warning> This endpoint allows you to upload entities in bulk.
Parameters
----------
project_id : str
Unique identifier of the project
request : ResolutionUploadBody
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionUploadResponse
Examples
--------
from sayari import Sayari
from sayari.resolution import ResolutionBody, ResolutionUploadBody
client = Sayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client.resolution.resolution_upload(
project_id="V03eYM",
request=ResolutionUploadBody(
filename="vbeck.json",
data=[
ResolutionBody(
name=["victoria beckham limited"],
tags=["spice girls"],
)
],
),
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v1/projects/{jsonable_encoder(project_id)}/resolutions",
method="POST",
json=convert_and_respect_annotation_metadata(
object_=request, annotation=ResolutionUploadBody, direction="write"
),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionUploadResponse,
parse_obj_as(
type_=ResolutionUploadResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 500:
raise InternalServerError(
typing.cast(
InternalServerErrorResponse,
parse_obj_as(
type_=InternalServerErrorResponse, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
class AsyncResolutionClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._client_wrapper = client_wrapper
async def resolution(
self,
*,
limit: typing.Optional[int] = None,
offset: typing.Optional[int] = None,
name: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
address: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
city: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
state: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
country: typing.Optional[typing.Union[Country, typing.Sequence[Country]]] = None,
identifier: typing.Optional[typing.Union[BothIdentifierTypes, typing.Sequence[BothIdentifierTypes]]] = None,
date_of_birth: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
contact: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
type: typing.Optional[typing.Union[Entities, typing.Sequence[Entities]]] = None,
profile: typing.Optional[ProfileEnum] = None,
name_min_percentage: typing.Optional[int] = None,
name_min_tokens: typing.Optional[int] = None,
minimum_score_threshold: typing.Optional[int] = None,
search_fallback: typing.Optional[bool] = None,
cutoff_threshold: typing.Optional[int] = None,
candidate_pool_size: typing.Optional[int] = None,
skip_post_process: typing.Optional[bool] = None,
enable_llm_clean: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ResolutionResponse:
"""
The resolution endpoints allow users to search for matching entities against a provided list of attributes. The endpoint is similar to the search endpoint, except it's tuned to only return the best match so the client doesn't need to do as much or any post-processing work to filter down results.
Parameters
----------
limit : typing.Optional[int]
A limit on the number of objects to be returned with a range between 1 and 10 inclusive. Defaults to 10.
offset : typing.Optional[int]
Number of results to skip before returning response. Defaults to 0.
name : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity name
address : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity address. For optimal matching results, it's recommended to concatenate the full address string (street, city, state, postal code).
city : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity city that contains the provided city name.
state : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity state that contains the provided state name.
country : typing.Optional[typing.Union[Country, typing.Sequence[Country]]]
Entity country - must be ISO (3166) Trigram i.e., `USA`. See complete list [here](/sayari-library/ontology/enumerated-types#country)
identifier : typing.Optional[typing.Union[BothIdentifierTypes, typing.Sequence[BothIdentifierTypes]]]
Entity identifier. Can be from either the [Identifier Type](/sayari-library/ontology/enumerated-types#identifier-type) or [Weak Identifier Type](/sayari-library/ontology/enumerated-types#weak-identifier-type) enums.
date_of_birth : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity date of birth
contact : typing.Optional[typing.Union[str, typing.Sequence[str]]]
Entity contact
type : typing.Optional[typing.Union[Entities, typing.Sequence[Entities]]]
[Entity type](/sayari-library/ontology/entities). If multiple values are passed for any field, the endpoint will match entities with ANY of the values.
profile : typing.Optional[ProfileEnum]
Specifies the search algorithm to use. `corporate` (default) is optimized for accurate entity attribute matching, ideal for business verification. `suppliers` is tailored for matching entities with trade data, suitable for supply chain use cases. `search` mimics /search/entity behavior, best for name-only matches.
name_min_percentage : typing.Optional[int]
Adding this param enables an alternative matching logic. It will set a minimum percentage of tokens needed to match with user input to be considered a "hit". Accepts integers from 0 to 100 inclusive.
name_min_tokens : typing.Optional[int]
Adding this param enables an alternative matching logic. It sets the minimum number of matching tokens the resolved hits need to have in common with the user input to be considered a "hit". Accepts non-negative integers.
minimum_score_threshold : typing.Optional[int]
Specifies the minimum score required to pass, which controls the strictness of the matching threshold. The default value is 77, and tuned for general use-case accuracy. Increase the value for stricter matching, reduce to loosen.
search_fallback : typing.Optional[bool]
Enables a name search fallback when either the corporate or supplier profiles fails to find a match. When invoked, the fallback will make a call similar to /search/entity on name only. By default set to false.
cutoff_threshold : typing.Optional[int]
Specifies the window of similar results returned in the match group. Increase for fewer multiple matches, decrease to open the aperture and allow for more matches. Default is .8
candidate_pool_size : typing.Optional[int]
Specifies the maximum number of entity candidates considered during search. Default is 50. Higher values increase match pool size but also increase latency.
skip_post_process : typing.Optional[bool]
Bypasses the post-processing setps and re-ranking. Useful for debugging. By default set to false, set to true to enable.
enable_llm_clean : typing.Optional[bool]
Whether to enable LLM-based data cleaning to remove noise and standardize entity attributes. Defaults to true if not supplied. Set to false to disable LLM cleaning.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionResponse
Examples
--------
import asyncio
from sayari import AsyncSayari
client = AsyncSayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
async def main() -> None:
await client.resolution.resolution(
name="Thomas Bangalter",
address="8 AVENUE RACHEL",
country="FRA",
)
asyncio.run(main())
"""
_response = await self._client_wrapper.httpx_client.request(
"v1/resolution",
method="GET",
params={
"limit": limit,
"offset": offset,
"name": name,
"address": address,
"city": city,
"state": state,
"country": country,
"identifier": identifier,
"date_of_birth": date_of_birth,
"contact": contact,
"type": type,
"profile": profile,
"name_min_percentage": name_min_percentage,
"name_min_tokens": name_min_tokens,
"minimum_score_threshold": minimum_score_threshold,
"search_fallback": search_fallback,
"cutoff_threshold": cutoff_threshold,
"candidate_pool_size": candidate_pool_size,
"skip_post_process": skip_post_process,
"enable_llm_clean": enable_llm_clean,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionResponse,
parse_obj_as(
type_=ResolutionResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 500:
raise InternalServerError(
typing.cast(
InternalServerErrorResponse,
parse_obj_as(
type_=InternalServerErrorResponse, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
async def resolution_post(
self,
*,
request: ResolutionBody,
limit: typing.Optional[int] = None,
offset: typing.Optional[int] = None,
enable_llm_clean: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ResolutionResponse:
"""
The resolution endpoints allow users to search for matching entities against a provided list of attributes. The endpoint is similar to the search endpoint, except it's tuned to only return the best match so the client doesn't need to do as much or any post-processing work to filter down results.
Parameters
----------
request : ResolutionBody
limit : typing.Optional[int]
A limit on the number of objects to be returned with a range between 1 and 10 inclusive. Defaults to 10.
offset : typing.Optional[int]
Number of results to skip before returning response. Defaults to 0.
enable_llm_clean : typing.Optional[bool]
Whether to enable LLM-based data cleaning to remove noise and standardize entity attributes. Defaults to true if not supplied. Set to false to disable LLM cleaning.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResolutionResponse
Examples
--------
import asyncio
from sayari import AsyncSayari
from sayari.resolution import ResolutionBody
client = AsyncSayari(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
async def main() -> None:
await client.resolution.resolution_post(
limit=1,
request=ResolutionBody(
name=["Thomas Bangalter"],
address=["8 AVENUE RACHEL"],
country=["FRA"],
),
)
asyncio.run(main())
"""
_response = await self._client_wrapper.httpx_client.request(
"v1/resolution",
method="POST",
params={
"limit": limit,
"offset": offset,
"enable_llm_clean": enable_llm_clean,
},
json=convert_and_respect_annotation_metadata(object_=request, annotation=ResolutionBody, direction="write"),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ResolutionResponse,
parse_obj_as(
type_=ResolutionResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequest(
typing.cast(
BadRequestResponse,
parse_obj_as(
type_=BadRequestResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 401:
raise Unauthorized(
typing.cast(
UnauthorizedResponse,
parse_obj_as(
type_=UnauthorizedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 405:
raise MethodNotAllowed(
typing.cast(
MethodNotAllowedResponse,
parse_obj_as(
type_=MethodNotAllowedResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 406:
raise NotAcceptable(
typing.cast(
NotAcceptableResponse,
parse_obj_as(
type_=NotAcceptableResponse, # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 429:
raise RateLimitExceeded(
typing.cast(
RateLimitResponse,
parse_obj_as(
type_=RateLimitResponse, # type: ignore
object_=_response.json(),
),