Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rnevarezc/pyostal
A lightweight Postal API Client for Python
https://github.com/rnevarezc/pyostal
api api-client client postal python
Last synced: 9 days ago
JSON representation
A lightweight Postal API Client for Python
- Host: GitHub
- URL: https://github.com/rnevarezc/pyostal
- Owner: rnevarezc
- License: mit
- Created: 2022-03-01T15:35:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-05T20:00:01.000Z (over 2 years ago)
- Last Synced: 2024-09-16T23:29:26.810Z (2 months ago)
- Topics: api, api-client, client, postal, python
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PYostal: Postal API Client
This library helps you use the [Postal](https://github.com/atech/postal) API in Python 3.9 (and above) to send Emails, get Message Details & Deliveries and Implement Events to handle Server Webhooks.
It uses [Requests](https://github.com/psf/requests) the simple, yet elegant HTTP library to handle all the http sorcery.
## Installing Requests and Supported Versions
PYostal is available on PyPI:
```bash
$ python -m pip install pyostal
```
PYostal officially supports Python 3.9+.## Usage
### Using the Client
You will need an API Credential from your Postal Installation to use the API Client.
```python
from pyostal.client import Client# Create a new Postal client using the server key of your Postal Installation.
client = Client('https://postal.yourdomain.com', 'your-api-key')# Optional: You can add any aditional Headers for your API installation
# (Maybe Authorization)
# You just add a dict with your headers:
headers = {
'Authorization' => 'Basic RTYtaO54BGBtcG9yYWwyMDIw'
}client = Client('https://postal.yourdomain.com', 'your-api-key', headers)
#Or you can add them manually to a Client Instance:
client.headers = headers
```### Sending an Email
Sending an email is simple. You can follow the example below:
```python
# Create a dict with the message:
payload = {
'to': ['[email protected]'],
'from_address': '[email protected]',
'reply_to': '[email protected]',
'subject': 'This is a subject',
'plain_body': 'This is a body'
}#send it using the client. that's it
response = client.send(payload)
```
Or Create a new Email instance and add manually each of the Mail attributes
```pythonfrom pyostal.emails import Email
email = Email({
'to': ['[email protected]'],
'bcc': ['[email protected]', '[email protected]'],
'from_address': '[email protected]',
'reply_to': '[email protected]',
'subject': 'This is a subject',
'plain_body': 'This is a body'
})email.add_cc('[email protected]')
email.html_body = "This is a HTML body
"# Here we get a pyostal.response.Response instance
response = client.send(Email)
```
## API InformationYou can get more information about the Postal API and Payloads in the [Postal Project Wiki](https://github.com/postalhq/postal/wiki/Using-the-API)
## Author
Rafael Nevarez