semvec/pypi-packages huggingface dataset:
mtpylon 0.0.3
Library to build backend with MTProto protocol
Requires Python: >=3.9

# mtpylon


![Running Tests](https://github.com/Zapix/mtpylon/workflows/Running%20Tests/badge.svg)
[![codecov](https://codecov.io/gh/Zapix/mtpylon/branch/dev/graph/badge.svg?token=4TWNMM7PCP)](https://codecov.io/gh/Zapix/mtpylon)

Library to build backend with MTProto's protocol

## Installation

```shell
pip install mtpylon
```

## Getting started

1. Generate rsa keys:

**rsa_keys.py:**

```python
from typing import List
import rsa  # type: ignore
from mtpylon.crypto import KeyPair  # type: ignore


def get_rsa_keys(count: int = 2) -> List[KeyPair]:
    rsa_list = [
        rsa.newkeys(nbits=2048)
        for _ in range(count)
    ]

    return [
        KeyPair(
            public=public,
            private=private
        ) for (public, private) in rsa_list
    ]
```


2. Declare schema for mtpylon

**schema.py:**

```python
import random
from dataclasses import dataclass

from aiohttp import web

from mtpylon import Schema


@dataclass
class Reply:
    rand_id: int
    content: str

    class Meta:
        name = 'reply'
        order = ('rand_id', 'content')


async def echo(request: web.Request, content: str) -> Reply:
    return Reply(
        rand_id=random.randint(1, 100),
        content=content
    )


schema = Schema(constructors=[Reply], functions=[echo])

```

3. Configure aiohttp with mtpylon

**web.py:**
```python
import sys
import logging

from aiohttp import web
import aiohttp_cors

from mtpylon.configuration import configure_app

from schema import schema as app_schema
from rsa_keys import get_rsa_keys

# create console handler and set level to debug
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(level=logging.DEBUG)

# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# add formatter to ch
ch.setFormatter(formatter)

logging.basicConfig(level=logging.DEBUG)


if __name__ == '__main__':
    app = web.Application()
    configure_app(
        app,
        app_schema,
        {
            'rsa_manager': {
                'params': {
                    'rsa_keys': get_rsa_keys()
                }
            },
            'pub_keys_path': '/pub-keys',
            'schema_path': '/schema',
        }
    )

    cors = aiohttp_cors.setup(
        app,
        defaults={
            '*': aiohttp_cors.ResourceOptions(
                allow_credentials=True,
                expose_headers="*",
                allow_headers="*",
            )
        }
    )

    for route in list(app.router.routes()):
        cors.add(route)

    web.run_app(app, port=8081)

```

4. Start it!

```shell
python web.py
```

5. to work with backend please try https://github.com/Zapix/zagram

## Documentation

For more information visit:

https://mtpylon.readthedocs.io/en/latest/

## Example:

Echo server: https://github.com/Zapix/echo-server
azcam-flaskserver 21.2.0
azcam extension for flask web server
Keywords: python

# azcam-flaskserver

*azcam-flaskserver* is an *azcam* extension which adds support for a flask-based web server.

## Installation

`pip install azcam-flaskserver`

or download from github: https://github.com/mplesser/azcam-flaskserver.git.

## Uage Example

```python
from azcam_flaskserver.flask_server import WebServer
webserver = WebServer()
webserver.templates_folder = azcam.db.systemfolder
webserver.index = f"index_mysystem.html"
webserver.start()
```
PLATER-GRAPH 1.9.8
Graph DB interface for Translator API
Requires Python: >=3.7

## PLATER

PLATER is a service to stand up REST endpoint over a neo4j or redis graph database.
There are some restrictions on the data structure of the Neo4j backend to be fully utilized through PLATER.

> **Data structure restrictions:**
> * All nodes should have an `id` to be searchable (Used in querying single Nodes)
> * All edges should have an `id` to be searchable (Used in generating ReasonerAPI)
> * Data is recommended to comply to the [Translator Reasoner API](https://github.com/NCATSTranslator/ReasonerAPI).

### Installation

To run the web server directly:

#### Create a virtual Environment and activate.

    cd <PLATER-ROOT>
    python<version> -m venv venv
    source venv/bin/activate
    
#### Install dependencies
    
    pip install -r PLATER/requirements.txt
    
 
#### Configure PLATER settings
   
   Populate `.env-template` file with settings and save as `.env` in repo root dir.
   
   ```bash   
    WEB_HOST=0.0.0.0
    WEB_PORT=8080
    DB_HOST=<neo4j_or_redis_address>
    DB_USERNAME=<user name required for neo4j, empty for redis>
    DB_PASSWORD=''
    DB_PORT=<redis port or neo4j http port>
    DB_NAME=<db name for redis, uses default db for neo4j>
    DB_TYPE=<use values 'redis' or 'neo4j'>
    PLATER_TITLE='Plater'
    PLATER_VERSION='1.0.0'
    

   ```
   
  
#### Run Script
  
    ./main.sh
 
    
 ### DOCKER 
   Or build an image and run it. 
  
  ```bash
    cd PLATER
    docker build --tag <image_tag> .
    cd ../
  ```
  
  ```bash
   docker run --env-file .env\
    --name plater\
    -p 8080:8080\
    --network <network_where_neo4j_is_running>\
    plater-tst

  ```
 
 ### Clustering with [Automat Server](https://github.com/RENCI-AUTOMAT/Automat-server/) \[Optional\]
 You can also serve several instances of plater through a common gateway(Automat). On specific instructions 
 please refer to [AUTOMAT's readme](https://github.com/RENCI-AUTOMAT/Automat-server/blob/master/README.md)
  
 

 ### Miscellaneous
 ###### `/about` Endpoint 
 The `/about` endpoint can be used to present meta-data about the current PLATER instance. 
 This meta-data is served from `<repo-root>/PLATER/about.json` file. One can edit the contents of
 this file to suite needs. In containerized environment we recommend mounting this file as a volume.
 
 Eg:
 ```bash
docker run -p 0.0.0.0:8999:8080  \
               --env DB_HOST=<your_db_host> \
               --env DB_PORT=<your_db_port> \
               --env DB_USERNAME=<db_user_name required for neo4j, ignored for redis> \
               --env DB_PASSWORD=<db_password> \
               --env DB_NAME=<required for redis> \ 
               --env DB_TYPE=<redis or neo4j> \  
               --env WEB_HOST=0.0.0.0 \
               -v <your-custom-about>:/<path-to-plater-repo-home>/plater/about.json \
               --network=<docker_network_neo4j_is_running_at> \    
                <image_tag>   
```