Skip to content

Commit e2ebb39

Browse files
authored
Merge pull request #13 from zerobounce/update/find-email-find-domain
Update/find email find domain
2 parents 765574a + 1e0dc58 commit e2ebb39

13 files changed

Lines changed: 997 additions & 37 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ docs/_build/
6060
target/
6161
\.idea/
6262
.vscode/
63+
.env

README.md

Lines changed: 279 additions & 9 deletions
Large diffs are not rendered by default.

documentation.md

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,39 @@ Import the sdk in your file:
1010
from zerobouncesdk import ZeroBounce
1111
```
1212

13-
Initialize the sdk with your api key:
13+
Initialize the SDK with your API key. You can optionally specify a base URL to use a different API region or a custom endpoint:
1414

15+
**Default**: Uses the default ZeroBounce API endpoint
1516
```python
17+
from zerobouncesdk import ZeroBounce
18+
1619
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
1720
```
1821

22+
**Using predefined API regions**: Use one of the available API regions
23+
```python
24+
from zerobouncesdk import ZeroBounce, ZBApiUrl
25+
26+
# Use USA region
27+
zero_bounce = ZeroBounce("<YOUR_API_KEY>", base_url=ZBApiUrl.API_USA_URL)
28+
29+
# Use EU region
30+
zero_bounce = ZeroBounce("<YOUR_API_KEY>", base_url=ZBApiUrl.API_EU_URL)
31+
32+
# Use default region (explicit)
33+
zero_bounce = ZeroBounce("<YOUR_API_KEY>", base_url=ZBApiUrl.API_DEFAULT_URL)
34+
```
35+
36+
**Using a custom URL string**: Provide your own base URL
37+
```python
38+
zero_bounce = ZeroBounce("<YOUR_API_KEY>", base_url="https://custom-api.example.com/v2")
39+
```
40+
41+
**Available API regions:**
42+
- `ZBApiUrl.API_DEFAULT_URL` - Default ZeroBounce API (https://api.zerobounce.net/v2/)
43+
- `ZBApiUrl.API_USA_URL` - USA region API (https://api-us.zerobounce.net/v2/)
44+
- `ZBApiUrl.API_EU_URL` - EU region API (https://api-eu.zerobounce.net/v2/)
45+
1946
#### Examples
2047
Then you can use any of the SDK methods, for example:
2148

@@ -61,23 +88,89 @@ except ZBException as e:
6188
print("ZeroBounce get_activity error: " + str(e))
6289
```
6390

64-
* ####### Identify the correct email format when you provide a name and email domain
91+
* ####### Find the correct email format when you provide a name and email domain or company name
92+
93+
```python
94+
from zerobouncesdk import ZeroBounce, ZBException
95+
96+
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
97+
98+
# Option 1: Use find_email_format with domain
99+
domain = "example.com" # The email domain for which to find the email format
100+
first_name = "John" # The first name of the person whose email format is being searched
101+
middle_name = "Quill" # Optional: The middle name of the person
102+
last_name = "Doe" # Optional: The last name of the person
103+
104+
try:
105+
response = zero_bounce.find_email_format(
106+
first_name=first_name,
107+
domain=domain,
108+
middle_name=middle_name,
109+
last_name=last_name
110+
)
111+
print("Email: " + str(response.email))
112+
print("Email Confidence: " + str(response.email_confidence))
113+
except ZBException as e:
114+
print("ZeroBounce find_email_format error: " + str(e))
115+
```
116+
117+
```python
118+
# Option 2: Use find_email_format with company_name
119+
from zerobouncesdk import ZeroBounce, ZBException
120+
121+
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
122+
123+
company_name = "Acme Corp" # The company name for which to find the email format
124+
first_name = "Jane" # The first name of the person
125+
126+
try:
127+
response = zero_bounce.find_email_format(
128+
first_name=first_name,
129+
company_name=company_name
130+
)
131+
print("Email: " + str(response.email))
132+
print("Domain: " + str(response.domain))
133+
print("Company: " + str(response.company_name))
134+
except ZBException as e:
135+
print("ZeroBounce find_email_format error: " + str(e))
136+
```
137+
138+
```python
139+
# Option 3: Use find_domain to discover email formats for a domain
140+
from zerobouncesdk import ZeroBounce, ZBException
141+
142+
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
143+
144+
domain = "example.com" # The email domain to analyze
145+
146+
try:
147+
response = zero_bounce.find_domain(domain=domain)
148+
print("Domain: " + str(response.domain))
149+
print("Format: " + str(response.format))
150+
print("Confidence: " + str(response.confidence))
151+
print("Other formats: " + str(len(response.other_domain_formats)))
152+
except ZBException as e:
153+
print("ZeroBounce find_domain error: " + str(e))
154+
```
65155

66156
```python
157+
# Option 4: Use find_domain with company_name
67158
from zerobouncesdk import ZeroBounce, ZBException
68159

69160
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
70161

71-
domain = "example.com" # The email domain for which to find the email format
72-
first_name = "John" # The first name of the person whose email format is being searched
73-
middle_name = "Quill" # The middle name of the person whose email format is being searched
74-
last_name = "Doe" # The last name of the person whose email format is being searched
162+
company_name = "Acme Corp" # The company name to analyze
75163

76164
try:
77-
response = zero_bounce.guess_format(domain, first_name, middle_name, last_name)
78-
print("ZeroBounce guess format response: " + response)
165+
response = zero_bounce.find_domain(company_name=company_name)
166+
print("Domain: " + str(response.domain))
167+
print("Company: " + str(response.company_name))
168+
print("Format: " + str(response.format))
169+
print("Confidence: " + str(response.confidence))
170+
for fmt in response.other_domain_formats:
171+
print(f" Alternative: {fmt.format} (confidence: {fmt.confidence})")
79172
except ZBException as e:
80-
print("ZeroBounce guess format error: " + str(e))
173+
print("ZeroBounce find_domain error: " + str(e))
81174
```
82175

83176
* ####### Validate an email address

documentation_es.md

Lines changed: 124 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,39 @@ Importa el SDK en tu archivo:
1010
from zerobouncesdk import ZeroBounce
1111
```
1212

13-
Inicializa el SDK con tu clave de API:
13+
Inicializa el SDK con tu clave de API. Puedes opcionalmente especificar una URL base para usar una región de API diferente o un endpoint personalizado:
1414

15+
**Por defecto**: Usa el endpoint predeterminado de ZeroBounce API
1516
```python
17+
from zerobouncesdk import ZeroBounce
18+
1619
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
1720
```
1821

22+
**Usando regiones de API predefinidas**: Usa una de las regiones de API disponibles
23+
```python
24+
from zerobouncesdk import ZeroBounce, ZBApiUrl
25+
26+
# Usar región USA
27+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>", base_url=ZBApiUrl.API_USA_URL)
28+
29+
# Usar región EU
30+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>", base_url=ZBApiUrl.API_EU_URL)
31+
32+
# Usar región predeterminada (explícita)
33+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>", base_url=ZBApiUrl.API_DEFAULT_URL)
34+
```
35+
36+
**Usando una URL personalizada**: Proporciona tu propia URL base
37+
```python
38+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>", base_url="https://custom-api.example.com/v2")
39+
```
40+
41+
**Regiones de API disponibles:**
42+
- `ZBApiUrl.API_DEFAULT_URL` - API predeterminada de ZeroBounce (https://api.zerobounce.net/v2/)
43+
- `ZBApiUrl.API_USA_URL` - API de región USA (https://api-us.zerobounce.net/v2/)
44+
- `ZBApiUrl.API_EU_URL` - API de región EU (https://api-eu.zerobounce.net/v2/)
45+
1946
#### Ejemplos
2047
Luego puedes utilizar cualquiera de los métodos del SDK, por ejemplo:
2148

@@ -62,23 +89,89 @@ except ZBException as e:
6289
```
6390

6491

65-
* ####### Identify the correct email format when you provide a name and email domain
92+
* ####### Encontrar el formato de correo electrónico correcto cuando proporcionas un nombre y un dominio o nombre de empresa
6693

6794
```python
6895
from zerobouncesdk import ZeroBounce, ZBException
6996

70-
zero_bounce = ZeroBounce("<YOUR_API_KEY>")
97+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
7198

72-
domain = "example.com" # The email domain for which to find the email format
73-
first_name = "John" # The first name of the person whose email format is being searched
74-
middle_name = "Quill" # The middle name of the person whose email format is being searched
75-
last_name = "Doe" # The last name of the person whose email format is being searched
99+
# Opción 1: Usar find_email_format con dominio
100+
dominio = "example.com" # El dominio de correo electrónico para encontrar el formato
101+
nombre = "John" # El nombre de la persona cuyo formato de correo se está buscando
102+
segundo_nombre = "Quill" # Opcional: El segundo nombre de la persona
103+
apellido = "Doe" # Opcional: El apellido de la persona
76104

77105
try:
78-
response = zero_bounce.guess_format(domain, first_name, middle_name, last_name)
79-
print("ZeroBounce guess format response: " + response)
106+
response = zero_bounce.find_email_format(
107+
first_name=nombre,
108+
domain=dominio,
109+
middle_name=segundo_nombre,
110+
last_name=apellido
111+
)
112+
print("Correo: " + str(response.email))
113+
print("Confianza del correo: " + str(response.email_confidence))
80114
except ZBException as e:
81-
print("ZeroBounce guess format error: " + str(e))
115+
print("Error de ZeroBounce find_email_format: " + str(e))
116+
```
117+
118+
```python
119+
# Opción 2: Usar find_email_format con company_name
120+
from zerobouncesdk import ZeroBounce, ZBException
121+
122+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
123+
124+
nombre_empresa = "Acme Corp" # El nombre de la empresa para encontrar el formato de correo
125+
nombre = "Jane" # El nombre de la persona
126+
127+
try:
128+
response = zero_bounce.find_email_format(
129+
first_name=nombre,
130+
company_name=nombre_empresa
131+
)
132+
print("Correo: " + str(response.email))
133+
print("Dominio: " + str(response.domain))
134+
print("Empresa: " + str(response.company_name))
135+
except ZBException as e:
136+
print("Error de ZeroBounce find_email_format: " + str(e))
137+
```
138+
139+
```python
140+
# Opción 3: Usar find_domain para descubrir formatos de correo para un dominio
141+
from zerobouncesdk import ZeroBounce, ZBException
142+
143+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
144+
145+
dominio = "example.com" # El dominio de correo electrónico a analizar
146+
147+
try:
148+
response = zero_bounce.find_domain(domain=dominio)
149+
print("Dominio: " + str(response.domain))
150+
print("Formato: " + str(response.format))
151+
print("Confianza: " + str(response.confidence))
152+
print("Otros formatos: " + str(len(response.other_domain_formats)))
153+
except ZBException as e:
154+
print("Error de ZeroBounce find_domain: " + str(e))
155+
```
156+
157+
```python
158+
# Opción 4: Usar find_domain con company_name
159+
from zerobouncesdk import ZeroBounce, ZBException
160+
161+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
162+
163+
nombre_empresa = "Acme Corp" # El nombre de la empresa a analizar
164+
165+
try:
166+
response = zero_bounce.find_domain(company_name=nombre_empresa)
167+
print("Dominio: " + str(response.domain))
168+
print("Empresa: " + str(response.company_name))
169+
print("Formato: " + str(response.format))
170+
print("Confianza: " + str(response.confidence))
171+
for fmt in response.other_domain_formats:
172+
print(f" Alternativa: {fmt.format} (confianza: {fmt.confidence})")
173+
except ZBException as e:
174+
print("Error de ZeroBounce find_domain: " + str(e))
82175
```
83176

84177
* ####### Validar una dirección de correo electrónico
@@ -272,3 +365,24 @@ try:
272365
except ZBException as e:
273366
print("ZeroBounce delete_file error: " + str(e))
274367
```
368+
369+
* ####### (Deprecado) Identificar el formato de correo electrónico correcto cuando proporcionas un nombre y un dominio de correo electrónico
370+
371+
> **⚠️ Deprecado:** El método `guess_format` está deprecado y se eliminará en futuras versiones. Use `find_email_format` o `find_domain` en su lugar (vea los ejemplos arriba).
372+
373+
```python
374+
from zerobouncesdk import ZeroBounce, ZBException
375+
376+
zero_bounce = ZeroBounce("<TU_CLAVE_DE_API>")
377+
378+
domain = "example.com" # El dominio de correo electrónico para encontrar el formato de correo
379+
first_name = "John" # El nombre de la persona cuyo formato de correo se está buscando
380+
middle_name = "Quill" # El segundo nombre de la persona cuyo formato de correo se está buscando
381+
last_name = "Doe" # El apellido de la persona cuyo formato de correo se está buscando
382+
383+
try:
384+
response = zero_bounce.guess_format(domain, first_name, middle_name, last_name)
385+
print("ZeroBounce guess format response: " + response)
386+
except ZBException as e:
387+
print("ZeroBounce guess format error: " + str(e))
388+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zerobouncesdk"
7-
version = "1.1.2"
7+
version = "2.0.0"
88
description = "ZeroBounce Python API - https://www.zerobounce.net."
99
readme = "README.md"
1010
authors = [{ name = "ZeroBounce", email = "support@zerobounce.net" }]

src/zerobouncesdk/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .zb_api_url import ZBApiUrl
12
from .zb_confidence import ZBConfidence
23
from .zb_exceptions import ZBException, ZBApiException, ZBClientException
34
from .zb_get_credits_response import ZBGetCreditsResponse
@@ -13,5 +14,7 @@
1314
from .zb_get_file_response import ZBGetFileResponse
1415
from .zb_delete_file_response import ZBDeleteFileResponse
1516
from .zb_guess_format_response import ZBGuessFormatResponse
17+
from .zb_find_email_format_response import ZBFindEmailFormatResponse
18+
from .zb_find_domain_response import ZBFindDomainResponse
1619

1720
from .zerobouncesdk import ZeroBounce

src/zerobouncesdk/zb_api_url.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from enum import Enum
2+
3+
4+
class ZBApiUrl(Enum):
5+
"""Enumeration of available ZeroBounce API base URLs."""
6+
7+
API_DEFAULT_URL = "https://api.zerobounce.net/v2/"
8+
API_USA_URL = "https://api-us.zerobounce.net/v2/"
9+
API_EU_URL = "https://api-eu.zerobounce.net/v2/"
10+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import List
2+
3+
from . import ZBConfidence, ZBApiException
4+
from ._zb_response import ZBResponse
5+
from .zb_guess_format_response import ZBDomainFormat
6+
7+
8+
class ZBFindDomainResponse(ZBResponse):
9+
"""This is the response for the find_domain request."""
10+
11+
domain: str = None
12+
"""The domain that was used or found."""
13+
14+
company_name: str = None
15+
"""The company name that was used or found."""
16+
17+
format: str = None
18+
"""The guessed email format for the domain."""
19+
20+
confidence: ZBConfidence = None
21+
"""The confidence level for the guessed format."""
22+
23+
did_you_mean: str = None
24+
"""Suggestive fix for any input errors."""
25+
26+
failure_reason: str = None
27+
"""Reason for failure if the operation was unsuccessful."""
28+
29+
other_domain_formats: List[ZBDomainFormat] = []
30+
"""List of other possible domain formats with their confidence levels."""
31+
32+
def __init__(self, data):
33+
super().__init__(data)
34+
if "Message" in data or "message" in data:
35+
message = data.get("message", data["Message"])
36+
raise ZBApiException(message)
37+
38+
if self.confidence and isinstance(self.confidence, str):
39+
self.confidence = ZBConfidence(self.confidence.lower())
40+
41+
self.other_domain_formats = [
42+
ZBDomainFormat(df_data) for df_data in data.get("other_domain_formats", [])
43+
]
44+

0 commit comments

Comments
 (0)