<commit_before>sendwithus python-client
========================

[![Build Status](https://travis-ci.org/sendwithus/sendwithus_python.png)](https://travis-ci.org/sendwithus/sendwithus_python)

## requirements
python requests library

## installation
	pip install sendwithus

## to run tests
	python setup.py test 

## usage

For all examples, assume:
```python
import sendwithus
api = sendwithus.api(api_key='YOUR-API-KEY')
```

# Emails

## Get your emails

```python
api.emails()
```

## Create an email

```python
api.create_email(
    name='<NAME>',
    subject='Email Subject',
    html='<html><head></head><body>Valid HTML</body></html>',
    text='Optional text content')
```

We validate all HTML and will return an error if it's invalid.

```python
r.status_code
# 400
r.content
# 'email html failed to validate'
```

## Deactive a drip campaign

You can deactivate pending drip campaign emails for a customer

```python
api.drip_deactivate('<EMAIL>')
```

# Send

### Call with REQUIRED parameters only
The `email_data` field is optional, but highly recommended!

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={'address': '<EMAIL>'})
print r.status_code
# 200
```

### Call with REQUIRED parameters and email_data
```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' })
print r.status_code
# 200
```

### Optional Sender
The `sender['address']` is a required sender field

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={ 'name': 'Matt',
                'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' },
    sender={ 'address':'<EMAIL>' })
print r.status_code
# 200
```

### Optional Sender with reply_to address
`sender['name']` and `sender['reply_to']` are both optional

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={ 'name': 'Matt',
                'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' },
    sender={ 'name': 'Company',
                'address':'<EMAIL>',
                'reply_to':'<EMAIL>'})
print r.status_code
# 200
```

## expected response

### Success 
	>>> r.status_code
	200

	>>> r.json().get('success')
	True

	>>> r.json().get('status')
	u'OK'

	>>> r.json().get('receipt_id')
	u'numeric-receipt-id'

### Error cases
* malformed request
	
		>>> r.status_code
		400

* bad api key

		>>> r.status_code    
	    	403

### packaging (internal)
        python setup.py sdist upload

<commit_msg>updat4e readme<commit_after>sendwithus python-client
========================

[![Build Status](https://travis-ci.org/sendwithus/sendwithus_python.png)](https://travis-ci.org/sendwithus/sendwithus_python)

## requirements
python requests library

## installation
	pip install sendwithus

## to run tests
	python setup.py test 

## usage

For all examples, assume:
```python
import sendwithus
api = sendwithus.api(api_key='YOUR-API-KEY')
```

# Emails

## Get your emails

```python
api.emails()
```

## Create an email

```python
api.create_email(
    name='Email Name',
    subject='Email Subject',
    html='<html><head></head><body>Valid HTML</body></html>',
    text='Optional text content')
```

We validate all HTML and will return an error if it's invalid.

```python
r.status_code
# 400
r.content
# 'email html failed to validate'
```

# Drip Campaigns

## Deactive a drip campaign

You can deactivate pending drip campaign emails for a customer

```python
api.drip_deactivate('<EMAIL>')
```

# Send

### Call with REQUIRED parameters only
The `email_data` field is optional, but highly recommended!

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={'address': '<EMAIL>'})
print r.status_code
# 200
```

### Call with REQUIRED parameters and email_data
```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' })
print r.status_code
# 200
```

### Optional Sender
The `sender['address']` is a required sender field

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={ 'name': 'Matt',
                'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' },
    sender={ 'address':'<EMAIL>' })
print r.status_code
# 200
```

### Optional Sender with reply_to address
`sender['name']` and `sender['reply_to']` are both optional

```python
r = api.send(
    email_id='YOUR-EMAIL-ID',
    recipient={ 'name': 'Matt',
                'address': '<EMAIL>'},
    email_data={ 'first_name': 'Matt' },
    sender={ 'name': 'Company',
                'address':'<EMAIL>',
                'reply_to':'<EMAIL>'})
print r.status_code
# 200
```

## expected response

### Success 
	>>> r.status_code
	200

	>>> r.json().get('success')
	True

	>>> r.json().get('status')
	u'OK'

	>>> r.json().get('receipt_id')
	u'numeric-receipt-id'

### Error cases
* malformed request
	
		>>> r.status_code
		400

* bad api key

		>>> r.status_code    
	    	403

### packaging (internal)
        python setup.py sdist upload


{'fraction_non_alphanumeric': 0.1793034825870647, 'fraction_numerical': 0.009751243781094527, 'mean_word_length': 3.8095693779904307, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 68, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4450581', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1692, 'n_words': 424}