Skip to main content

AndEggs

AndEggs is a Python library that allows you to create an email bot using Gmail's API.

Simple Documentation

Client Class

The Client class will be the main entry point of your program.

Create a Client

First, create a new client by calling the Client constructor:

    >>> from andeggs import Client
    >>> client = Client('CommandPrefix')

Then, you can use the Client object to interact with Gmail's API.

Creating a Command

To create a command, you should create an asynchronous function that will be called when the command is triggered. It should take in a MailContext object as its only parameter. This object contains all the information about the email that triggered the command. To turn it into a command, use the Client.command decorator:

    >>> @client.command('CommandName')
    >>> async def command(context: MailContext):
    >>>     # Do something
    >>>     pass

Sending an Email

To send an email, you should use the Client.send method:

    >>> client.send(
    >>>     to='RecipientEmail',
    >>>     subject='Subject',
    >>>     body='Body',
    >>>     is_html=False,
    >>> )

Activating the Client

To activate the client, you should call the Client.run method:

    >>> client.run('youremail', 'yourpassword')

Events

Events are triggered when certain actions happen. Below is a list of the events that can be triggered and their parameters:

  • on_ready: Triggered when the client is started.
  • on_message: Triggered when a new email is received. The parameter is a MailContext object.
  • on_send: Triggered when an email is sent. The parameter is a MailContext object.
  • on_command: Triggered when a command is triggered. The parameter is a MailContext object.
  • on_stop: Triggered when the client is stopped.

Tasks

A task is a function that runs in the background. You can use the Client.task decorator to create a task:

    >>> @client.task(interval=60)
    >>> async def task():
    >>>     # Do something
    >>>     pass

MailContext

On all of your commands, you will receive a MailContext object. This object contains all the information about the email that triggered the command.

Attributes

  • sender: A Sender object.
  • subject: The subject of the email.
  • body: The body of the email.

Sending an Email

You can also send an email using the MailContext.send method:

    >>> context.send(
    >>>     'Body',
    >>> )

If you want to format your text with html, you should use the MailContext.sendf method:

    >>> context.sendf(
    >>>     '<p>{}</p>',
    >>>     'Body',
    >>> )

Release files for and-eggs 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for and-eggs 0.0.7
File Interpreter ABI Platform
and_eggs-0.0.7-py3-none-any.whl Python 3 none any Details

Release files / and_eggs-0.0.7-py3-none-any.whl

Download URL and_eggs-0.0.7-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6a5c7a7e6b1fae7e766e95aa6a18748c973f1e970d955bd793836a867e165b0
BLAKE2b-256 checksum
How to use checksums
707c21fb9cd942139002b3cfbfeae0d5eaaaeba31f6e84b73188dd033768ebd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.8.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page