User Guide

Requirements

  • Python 3.5 or later is required to use the new async/await syntax provided by the asyncio library.
  • SpamAssassin running as a service.

Install

With PIP

pip install aiospamc

With GIT

git clone https://github.com/mjcaley/aiospamc.git
python3 aiospamc/setup.py install

How to use aiospamc

Instantiating the aiospamc.client.Client class will be the primary way to interact with aiospamc.

Parameters are available to specify how to connect to the SpamAssassin SPAMD service including host, port, and whether SSL is enabled. They default to localhost, 783, and SSL being disabled. Additional optional parameters are the username that requests will be sent as (no user by default) and whether to compress the request body (disabled by default).

A coroutine method is available for each type of request that can be sent to SpamAssassin.

An example using the aiospamc.client.Client.check() method:

Other requests can be seen in the aiospamc.client.Client class.

Making your own requests

If a request that isn’t built into aiospamc is needed a new request can be created and sent.

A new request can be made by instantiating the aiospamc.requests.Request class. The aiospamc.requests.Request.verb defines the method/verb of the request.

Standard headers or the aiospamc.headers.XHeader extension header is available in the aiospamc.headers module. Headers are managed on the request object with the methods:

Once a request is composed, it can be sent through the aiospamc.client.Client.send() method as-is. The method will automatically add the aiospamc.headers.User and aiospamc.headers.Compress headers if required.

For example:

Interpreting results

Responses are encapsulated in the aiospamc.responses.Response class. It includes the status code, headers and body.