Skip to content

Commit 00360d5

Browse files
committed
Add readme
1 parent dbe08b8 commit 00360d5

File tree

1 file changed

+236
-1
lines changed

1 file changed

+236
-1
lines changed

README.md

Lines changed: 236 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,237 @@
11
# poodle-python
2-
Poodle Python SDK
2+
3+
Python SDK for Poodle's email sending API.
4+
5+
## Table of Contents
6+
7+
- [Installation](#installation)
8+
- [Quick Start](#quick-start)
9+
- [Features](#features)
10+
- [Examples](#examples)
11+
- [API Reference](#api-reference)
12+
- [Development](#development)
13+
- [Contributing](#contributing)
14+
- [License](#license)
15+
16+
## Installation
17+
18+
```bash
19+
pip install poodle-python
20+
```
21+
22+
## Quick Start
23+
24+
```python
25+
from poodle import PoodleClient
26+
27+
# Initialize the client
28+
client = PoodleClient("your-api-key")
29+
30+
# Send an email
31+
try:
32+
response = client.send_email(
33+
from_email="[email protected]",
34+
to_email="[email protected]",
35+
subject="Hello from Poodle!",
36+
html_content="<h1>Hello World</h1>",
37+
text_content="Hello World" # Optional plain text version
38+
)
39+
print(f"Success: {response['message']}")
40+
except PoodleError as e:
41+
print(f"Error: {e.message}")
42+
if e.status_code:
43+
print(f"Status Code: {e.status_code}")
44+
if e.details:
45+
print(f"Details: {e.details}")
46+
```
47+
48+
## Features
49+
50+
- **Intuitive API**: Get started in minutes.
51+
- **Detailed Errors**: Understand and debug issues quickly with PoodleError objects.
52+
- **Flexible Content**: Send rich HTML or plain text emails easily.
53+
- **Connection Pooling**: Optimize performance with connection pooling.
54+
- **Type Hints**: Better IDE support with type hints.
55+
- **Context Manager**: Proper resource cleanup with context manager.
56+
57+
## Examples
58+
59+
### Initialize with Custom Options
60+
61+
```python
62+
client = PoodleClient(
63+
api_key="your-api-key",
64+
base_url="https://custom.api.url", # Optional custom API URL
65+
timeout=60.0 # Optional custom timeout in seconds
66+
)
67+
```
68+
69+
### Send HTML-only Email
70+
71+
```python
72+
response = client.send_email(
73+
from_email="[email protected]",
74+
to_email="[email protected]",
75+
subject="HTML Email",
76+
html_content="<h1>Hello</h1><p>This is an HTML email</p>"
77+
)
78+
```
79+
80+
### Send Plain Text Email
81+
82+
```python
83+
response = client.send_email(
84+
from_email="[email protected]",
85+
to_email="[email protected]",
86+
subject="Plain Text Email",
87+
text_content="Hello! This is a plain text email."
88+
)
89+
```
90+
91+
### Using as Context Manager
92+
93+
```python
94+
with PoodleClient("your-api-key") as client:
95+
response = client.send_email(
96+
from_email="[email protected]",
97+
to_email="[email protected]",
98+
subject="Test Email",
99+
text_content="Hello World"
100+
)
101+
```
102+
103+
### Error Handling
104+
105+
```python
106+
try:
107+
response = client.send_email(...)
108+
except PoodleError as e:
109+
print(f"An API Error occurred: {e.message}")
110+
if e.status_code == 429: # Rate limit exceeded
111+
# The PoodleError __str__ method will format this nicely.
112+
# e.details will contain the specific error string from the API.
113+
print(str(e))
114+
if e.details:
115+
print(f"Rate limit details: {e.details}")
116+
elif e.status_code == 400: # Validation error
117+
print(f"Validation error: {e.message}")
118+
if e.details:
119+
print(f"Validation details: {e.details}")
120+
elif e.status_code:
121+
print(f"Status Code: {e.status_code}")
122+
if e.details:
123+
print(f"Error details: {e.details}")
124+
else:
125+
# Network error or other non-HTTP error (e.details will be None)
126+
print(f"Error: {e}")
127+
```
128+
129+
## API Reference
130+
131+
### PoodleClient
132+
133+
#### Constructor
134+
135+
```python
136+
PoodleClient(
137+
api_key: str,
138+
base_url: Optional[str] = None,
139+
timeout: Optional[float] = None
140+
)
141+
```
142+
143+
- `api_key`: Your Poodle API key (required)
144+
- `base_url`: Optional custom API base URL
145+
- `timeout`: Optional custom timeout for API requests in seconds
146+
147+
#### Methods
148+
149+
##### send_email
150+
151+
```python
152+
send_email(
153+
from_email: str,
154+
to_email: str,
155+
subject: str,
156+
html_content: Optional[str] = None,
157+
text_content: Optional[str] = None
158+
) -> Dict[str, Any]
159+
```
160+
161+
Sends an email using the Poodle API.
162+
163+
**Parameters:**
164+
165+
- `from_email`: The sender's email address
166+
- `to_email`: The recipient's email address
167+
- `subject`: The email subject line
168+
- `html_content`: Optional HTML content for the email
169+
- `text_content`: Optional plain text content for the email
170+
171+
**Returns:**
172+
A dictionary containing at least:
173+
174+
- `success`: Boolean indicating success
175+
- `message`: Success message from the API
176+
177+
**Raises:**
178+
179+
- `PoodleError`: If the API request fails or returns an error
180+
181+
### PoodleError
182+
183+
Custom exception class for Poodle-related errors.
184+
185+
**Attributes:**
186+
187+
- `message`: Human-readable error message (from API `message` field)
188+
- `status_code`: HTTP status code from the API (if applicable)
189+
- `details`: Optional string containing additional error details from the API (from API `error` field, or `None`)
190+
191+
## Development
192+
193+
### Setup Development Environment
194+
195+
1. Clone the repository:
196+
197+
```bash
198+
git clone https://github.com/usepoodle/poodle-python.git
199+
cd poodle-python
200+
```
201+
202+
2. Install development dependencies:
203+
204+
```bash
205+
pip install poetry
206+
poetry install
207+
```
208+
209+
### Running Tests
210+
211+
```bash
212+
poetry run pytest
213+
```
214+
215+
### Code Style
216+
217+
This project uses:
218+
219+
- Black for code formatting
220+
- Flake8 for linting
221+
- MyPy for type checking
222+
223+
To check code style:
224+
225+
```bash
226+
poetry run black .
227+
poetry run flake8
228+
poetry run mypy poodle
229+
```
230+
231+
## Contributing
232+
233+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on the process for submitting pull requests and our [Code of Conduct](CODE_OF_CONDUCT.md).
234+
235+
## License
236+
237+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)