|
| 1 | +nameapi-client-python |
| 2 | +=================== |
| 3 | + |
| 4 | +Python Client for the NameAPI Web Services at https://www.nameapi.org. |
| 5 | + |
| 6 | +There are functional tests that demonstrate how to use this library. |
| 7 | + |
| 8 | +All you need to send requests is your own api key which you can get from nameapi.org. |
| 9 | + |
| 10 | +This library requires at least Python 3.8. |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## Library setup |
| 15 | + |
| 16 | +Create virtual environment and activate it: |
| 17 | + |
| 18 | + python -m venv myenv |
| 19 | + myenv\Scripts\activate |
| 20 | + |
| 21 | +Install the required libraries: |
| 22 | + |
| 23 | + pip install -r requirements.txt |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Send a ping |
| 28 | + |
| 29 | +This code sends a simple ping to nameapi to test the connection: |
| 30 | + |
| 31 | + |
| 32 | +```python |
| 33 | +client = NameApiClient(None) |
| 34 | +response = client.ping() # return the string 'pong' |
| 35 | +``` |
| 36 | + |
| 37 | +## Input / Output |
| 38 | + |
| 39 | + |
| 40 | +#### Person input object |
| 41 | + |
| 42 | +Most services accept a 'Person' as input. This person contains a name, and optionally |
| 43 | +more data such as gender, birth date etc. |
| 44 | +The name can be just a single "full name" string, or it can be composed of multiple |
| 45 | +fields like given name, middle name, surname. |
| 46 | +This standardized api makes it simple to use different services in a consistent way, |
| 47 | +and is very convenient in accepting the data however you have it at hands. |
| 48 | + |
| 49 | +Creating a simple person looks something like this: |
| 50 | + |
| 51 | +```python |
| 52 | +name_object = WesternInputPersonNameBuilder().fullname("Petra Müller").build() |
| 53 | +input_person = NaturalInputPersonBuilder().name(name_object).build() |
| 54 | +``` |
| 55 | + |
| 56 | +Creating name objects: |
| 57 | + |
| 58 | +```python |
| 59 | +name_object_1 = WesternInputPersonNameBuilder() \ |
| 60 | + .fullname("Petra Müller") \ |
| 61 | + .build() |
| 62 | + |
| 63 | +name_object_2 = WesternInputPersonNameBuilder() \ |
| 64 | + .given_name("Petra") \ |
| 65 | + .surname("Müller") \ |
| 66 | + .build() |
| 67 | + |
| 68 | +name_object_3 = WesternInputPersonNameBuilder() \ |
| 69 | + .name_field(NameField("Petra", CommonNameFieldType.GIVENNAME)) \ |
| 70 | + .name_field(NameField("Müller", CommonNameFieldType.SURNAME)) \ |
| 71 | + .name_field(NameField("Alexa", AmericanNameFieldType.MIDDLENAME)) \ |
| 72 | + .build() |
| 73 | + |
| 74 | +name_object_4 = InputPersonName([NameField("petra müller", CommonNameFieldType.FULLNAME)]) |
| 75 | +``` |
| 76 | + |
| 77 | +Creating complex input person objects: |
| 78 | + |
| 79 | +```python |
| 80 | +input_person = NaturalInputPersonBuilder() \ |
| 81 | + .name(name_object_1) \ |
| 82 | + .gender(StoragePersonGender.MALE) \ |
| 83 | + |
| 84 | + .add_tel_number("+5555555") \ |
| 85 | + .age(BirthDate(year=1999, month=2, day=1))\ |
| 86 | + .build() |
| 87 | +``` |
| 88 | + |
| 89 | +#### Result objects |
| 90 | + |
| 91 | +Response from the requests, displayed as json: https://api.nameapi.org/rest/swagger-ui/ |
| 92 | + |
| 93 | +Access the link above to see all the return type and their json format. |
| 94 | + |
| 95 | + |
| 96 | +## Commands |
| 97 | + |
| 98 | +The web service methods are implemented as commands. This brings the advantage that the |
| 99 | +command can be passed around and wrapped with other useful goodies such as logging |
| 100 | +in a unified way, without the need to put a wrapper around every service. |
| 101 | +For more specialized concerns such as auto-retry on failure this concept becomes |
| 102 | +a real advantage. |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +## Name Parser |
| 107 | + |
| 108 | +Name parsing is the process of splitting a full name into its components. |
| 109 | + |
| 110 | + |
| 111 | +```python |
| 112 | +api_key = None # Set your api_key here |
| 113 | +client = NameApiClient(api_key) |
| 114 | +response = client.person_name_parser(input_person_1) |
| 115 | +``` |
| 116 | + |
| 117 | + |
| 118 | +## Name Genderizer |
| 119 | + |
| 120 | +Name genderizing is the process of identifying the gender based on a person's name. |
| 121 | + |
| 122 | + |
| 123 | +```python |
| 124 | +api_key = None # Set your api_key here |
| 125 | +client = NameApiClient(api_key) |
| 126 | +response = client.person_genderizer(input_person_1) |
| 127 | +``` |
| 128 | + |
| 129 | + |
| 130 | +## Name Matcher |
| 131 | + |
| 132 | +The Name Matcher compares names and name pairs to discover whether the people could possibly be one and the same person. |
| 133 | + |
| 134 | +This service takes 2 people as input: |
| 135 | + |
| 136 | +```python |
| 137 | +api_key = None # Set your api_key here |
| 138 | +client = NameApiClient(api_key) |
| 139 | +response = client.person_matcher(input_person_1, input_person_2) |
| 140 | +``` |
| 141 | + |
| 142 | + |
| 143 | +## Name Formatter |
| 144 | + |
| 145 | +The Name Formatter displays personal names in the desired form. This includes the order as well as upper and lower case writing. |
| 146 | + |
| 147 | +```python |
| 148 | +api_key = None # Set your api_key here |
| 149 | +client = NameApiClient(api_key) |
| 150 | +response = client.person_name_formatter(input_person_1) |
| 151 | +``` |
| 152 | + |
| 153 | +## Risk Detector |
| 154 | + |
| 155 | +Detects various types of possibly fake data in person records. |
| 156 | + |
| 157 | +```python |
| 158 | +api_key = None # Set your api_key here |
| 159 | +client = NameApiClient(api_key) |
| 160 | +response = client.risk_detector(input_person_1) |
| 161 | +``` |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +## Email Name Parser |
| 166 | + |
| 167 | +The Email Name Parser extracts names out of email addresses. |
| 168 | + |
| 169 | +```python |
| 170 | +api_key = None # Set your api_key here |
| 171 | +client = NameApiClient(api_key) |
| 172 | + |
| 173 | +response = client.email_name_parser(email_address) |
| 174 | +``` |
| 175 | + |
| 176 | + |
| 177 | +## Disposable Email Address Detector |
| 178 | + |
| 179 | +The DEA-Detector checks email addresses against a list of known "trash domains" such as mailinator.com. |
| 180 | + |
| 181 | +```python |
| 182 | +api_key = None # Set your api_key here |
| 183 | +client = NameApiClient(api_key) |
| 184 | + |
| 185 | +response = client.disposable_email_detector(email_address) |
| 186 | +``` |
| 187 | + |
0 commit comments