semvec/pypi-packages huggingface dataset:
aiomatter 0.2.0
Mattermost async bot
Requires Python: >=3.11


# Aiomatter Bot

Aiomatter is a Python library for creating a bot that interacts with Mattermost via its API and WebSocket. This README provides instructions on setting up the bot and an example of a greeting plugin.

## Table of Contents
- [Installation](#installation)
- [Configuration](#configuration)
- [Running the Bot](#running-the-bot)
- [Example Greeting Plugin](#example-greeting-plugin)
- [License](#license)
- [Author](#author)

## Installation

To install Aiomatter, use pip:

```
pip install aiomatter
```

## Configuration

To configure the bot, you need to create a settings object with the following parameters:

- `bot_token`: Your Mattermost bot token.
- `base_url`: The base URL of your Mattermost server.
- `api_path`: The API path (default is `/api/v4`).

Example:

```
from aiomatter.settings import Settings

settings = Settings(
    bot_token='your_bot_token',
    base_url='https://chat.yourserver.com',
    api_path='/api/v4'
)
```

## Running the Bot

To run the bot, create an instance of the `Bot` class and call the `run` method:

```
from aiomatter.bot import Bot
from aiomatter.settings import Settings
from plugins import MyPlugin  # Your plugin

def get_bot() -> Bot:
    settings = Settings(
        bot_token='your_bot_token',
        base_url='https://chat.yourserver.com',
        api_path='/api/v4'
    )
    
    plugins = [MyPlugin()]

    return Bot(settings=settings, plugins=plugins)

if __name__ == '__main__':
    bot = get_bot()
    bot.run()
```

## Example Greeting Plugin

The following example demonstrates a simple greeting plugin that responds to the `POSTED` event.

```plugin.py
from aiomatter.plugin import Plugin
from aiomatter.wrappers import listen
from aiomatter.events import EventType
from aiomatter.schemas.events import PostEvent

class MyPlugin(Plugin):

    @listen(EventType.POSTED)
    async def hello(self, event: PostEvent):
        channel_id = event.data.post.channel_id  # Access channel_id from the typed event
        if channel_id:
            await self.driver.send_message(
                channel_id=channel_id,
                message='Hello!'
            )
            self.logger.info(f"Message sent to channel {channel_id}.")
```

### Note on Typing

In the plugin methods, the decorator processes the event and returns a typed event instead of a generic event. This enhances type safety and improves code readability.

## License

This project is licensed under the MIT License.

## Author

Vladimir Savelev - [GitHub Profile](https://github.com/savvlex)
Polina Grunina - [GitHub Profile](https://github.com/LynnG3)
linnworks-api-python 0.1.0
Linnworks API Python Client
Requires Python: <4.0,>=3.9

# linnworks-api-python

This is a python version of the Linnworks API
<https://apidocs.linnworks.net/reference/overview>

We use the openapi generator <https://openapi-generator.tech/> to convert the linnworks api
swagger api models <https://github.com/LinnSystems/PublicApiSpecs> into a python package.

This creates a `requests` based API with `pydantic` types. Awesome!

This project consists of tweaks I had to make to aws auth schemes to get things working
with the openapi generator client, the generator script that creates the models and a
little bit of documentation. Nothing fancy.

## Prerequisites

- python 3.9+
- linnworks api credentials. See the docs <https://apidocs.linnworks.net/reference/setting-up>

## Installation

`pip install linnworks-api-python`

## Usage

```python
import os
from linnworks_api.generated.auth.api import AuthApi
from linnworks_api.generated.auth.models.authorize_by_application_request import AuthorizeByApplicationRequest

from linnworks_api.generated.inventory.api import InventoryApi
from linnworks_api.generated.inventory.base_client import LinnworksConfig, LinnworksClient as InventoryClient

# Mock responses
from dotenv import load_dotenv

load_dotenv()


def test_auth():
    """This is an example of how to get an auth token"""
    props = AuthorizeByApplicationRequest(
        ApplicationId=os.getenv("LW_CLIENT_ID"),
        ApplicationSecret=os.getenv("LW_CLIENT_SECRET"),
        Token=os.getenv("LW_TOKEN"),
    )
    auth_api = AuthApi()
    response = auth_api.authorize_by_application(props)
    assert isinstance(response.token, str)


def test_inventory():
    """This is an example of how to create a client and make an API call"""
    inventory_client = InventoryClient(
        linnworks_config=LinnworksConfig(
            client_id=os.getenv("LW_CLIENT_ID"),
            client_secret=os.getenv("LW_CLIENT_SECRET"),
            token=os.getenv("LW_TOKEN"),
        )
    )
    inventory_api = InventoryApi(inventory_client)
    response = inventory_api.get_inventory_items_count()
    assert response == 1
```

## Development

This is a poetry project so do the normal `poetry install` type things to set up your environment. 

We use a Makefile for build automation.

- `make clean` removes the generated code
- `make generate` generates the schemas
- `make test` runs unit tests
- `make lint-fix` fixes linting issues and checks compliance with linting standards

### Project Structure

```text
.
├── Makefile - make scripts
├── README.md - this file
├── notebooks
│   └── api_test.ipynb - example usage
├── poetry.lock
├── pyproject.toml
├── PublicApiSpecs - the linnworks swagger models. A git submodule
├── scripts
│   └── generate_schemas.py - script to generate api
├── tests - unit tests. (just enough to make sure things generated without error)
└── src
    └── linnworks_api
        |── base_client.py - client that gets copied into each package in generated/
        └── generated - the generated api files created when generate_schemas.py is run
```