kandi background
Explore Kits

pyrogram | Telegram MTProto API Client Library and Framework in Pure Python | REST library

 by   pyrogram Python Version: v1.3.0 License: LGPL-3.0

 by   pyrogram Python Version: v1.3.0 License: LGPL-3.0

Download this library from

kandi X-RAY | pyrogram Summary

pyrogram is a Python library typically used in Telecommunications, Media, Telecom, Web Services, REST applications. pyrogram has no bugs, it has no vulnerabilities, it has build file available, it has a Weak Copyleft License and it has medium support. You can download it from GitHub.
Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots. Pyrogram is a modern, elegant and asynchronous MTProto API framework. It enables you to easily interact with the main Telegram API through a user account (custom client) or a bot identity (bot API alternative) using Python.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • pyrogram has a medium active ecosystem.
  • It has 2346 star(s) with 771 fork(s). There are 85 watchers for this library.
  • There were 1 major release(s) in the last 12 months.
  • There are 80 open issues and 434 have been closed. On average issues are closed in 47 days. There are 39 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of pyrogram is v1.3.0
pyrogram Support
Best in #REST
Average in #REST
pyrogram Support
Best in #REST
Average in #REST

quality kandi Quality

  • pyrogram has 0 bugs and 0 code smells.
pyrogram Quality
Best in #REST
Average in #REST
pyrogram Quality
Best in #REST
Average in #REST

securitySecurity

  • pyrogram has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • pyrogram code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
pyrogram Security
Best in #REST
Average in #REST
pyrogram Security
Best in #REST
Average in #REST

license License

  • pyrogram is licensed under the LGPL-3.0 License. This license is Weak Copyleft.
  • Weak Copyleft licenses have some restrictions, but you can use them in commercial projects.
pyrogram License
Best in #REST
Average in #REST
pyrogram License
Best in #REST
Average in #REST

buildReuse

  • pyrogram releases are available to install and integrate.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • pyrogram saves you 10151 person hours of effort in developing the same functionality from scratch.
  • It has 22958 lines of code, 849 functions and 350 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
pyrogram Reuse
Best in #REST
Average in #REST
pyrogram Reuse
Best in #REST
Average in #REST
Top functions reviewed by kandi - BETA

kandi has reviewed pyrogram and discovered the below as its top functions. This is intended to give you an instant insight into pyrogram implemented functionality, and help decide if they suit your requirements.

  • Return a pyrogram API endpoint .
  • Send a media group .
  • Send an animation .
  • Get a single file from storage .
  • Use this method to send a video .
  • Use this method to send audio files .
  • Create a new authentication key .
  • Saves a file to disk .
  • Copy message to chat .
  • Sends a document to a chat .

pyrogram Key Features

Ready: Install Pyrogram with pip and start building your applications right away.

Easy: Makes the Telegram API simple and intuitive, while still allowing advanced usages.

Elegant: Low-level details are abstracted and re-presented in a more convenient way.

Fast: Boosted up by TgCrypto, a high-performance crypto library written in pure C.

Type-hinted: Types and methods are all type-hinted, enabling excellent editor support.

Async: Fully asynchronous (also usable synchronously if wanted, for convenience).

Powerful: Full access to Telegram's API to execute any official client action and more.

Pyrogram

copy iconCopydownload iconDownload
from pyrogram import Client, filters

app = Client("my_account")


@app.on_message(filters.private)
async def hello(client, message):
    await message.reply("Hello from Pyrogram!")


app.run()

Installing

copy iconCopydownload iconDownload
pip3 install pyrogram

Monkey Patching in Python using super.__init__

copy iconCopydownload iconDownload
from pyrogram.types import Message

class MyMessage(Message):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @property
    def test(self):
        return "test"
-----------------------
from pyrogram.types import Message 

@property
def test(self):
       return "test"

Message.test = test
from pyrogram.types import Message 

Message.__init_subclass__ = classmethod(lambda sub: [setattr(Message, k, v) for (k,v) in sub.__dict__.items() if k[:2] != '__'])

class MyMessage(Message):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @property
    def test(self):
        return "test"
-----------------------
from pyrogram.types import Message 

@property
def test(self):
       return "test"

Message.test = test
from pyrogram.types import Message 

Message.__init_subclass__ = classmethod(lambda sub: [setattr(Message, k, v) for (k,v) in sub.__dict__.items() if k[:2] != '__'])

class MyMessage(Message):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @property
    def test(self):
        return "test"
-----------------------
def monkeypatch(obj):
    def wrapper(sub):
        for (func_name, func_) in sub.__dict__.items():
            if func_name[:2] != "__":
                setattr(obj, func_name, func_)
        return sub
    return wrapper
@monkeypatch(songobj)
class something:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
    def do_it(self):
        print("just an example")
-----------------------
def monkeypatch(obj):
    def wrapper(sub):
        for (func_name, func_) in sub.__dict__.items():
            if func_name[:2] != "__":
                setattr(obj, func_name, func_)
        return sub
    return wrapper
@monkeypatch(songobj)
class something:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
    def do_it(self):
        print("just an example")

Dont send message with inlinekeyboard pyrogram

copy iconCopydownload iconDownload
btn = pyrokbbut(text,url=url)
kb = pyrokbmk(inline_keyboard=[btn])
keyboard = [  # List of rows:
    [button, button],  # First Row
    [button],  # Second Row
]
-----------------------
btn = pyrokbbut(text,url=url)
kb = pyrokbmk(inline_keyboard=[btn])
keyboard = [  # List of rows:
    [button, button],  # First Row
    [button],  # Second Row
]

Split message with media content and without Telegram pyrogram Bot

copy iconCopydownload iconDownload
@app.on_message(filters.chat(SOURCE_CHAT_TEST))
def copy_to_channel(client, message):
    if message.text:
        if len(message.text) >= 300:
            for i in range(0, len(message.text), 300):
                client.send_message(
                    chat_id=TARGET_CHAT_TEST,
                    text=message.text[i:i+300])
        else:
            message.copy(  chat_id=TARGET_CHAT_TEST  )
    else:
        pass

Split message telegram bot pyrogram

copy iconCopydownload iconDownload
@app.on_message(filters.chat(SOURCE_CHAT_A))
def copy_to_channel(client, message):
    # split message text on double newlines
    messages = message.text.split("\n\n")
    # send each message to the target chat
    for message in messages:
        client.send_message(TARGET_CHAT_A, message)
@app.on_message(filters.chat(SOURCE_CHAT_A))
def copy_to_channel(client, message):
    # split message into batches of 300 characters
    for i in range(0, len(message.text), 300):
        client.send_message(
            chat_id=SOURCE_CHAT_B,
            text=message.text[i:i+300]
        )
-----------------------
@app.on_message(filters.chat(SOURCE_CHAT_A))
def copy_to_channel(client, message):
    # split message text on double newlines
    messages = message.text.split("\n\n")
    # send each message to the target chat
    for message in messages:
        client.send_message(TARGET_CHAT_A, message)
@app.on_message(filters.chat(SOURCE_CHAT_A))
def copy_to_channel(client, message):
    # split message into batches of 300 characters
    for i in range(0, len(message.text), 300):
        client.send_message(
            chat_id=SOURCE_CHAT_B,
            text=message.text[i:i+300]
        )

Is there a way to disable Pyrogram logging?

copy iconCopydownload iconDownload
import logging
logging.basicConfig(level=logging.WARNING)

Why the django run command "python3 manage.py runserver" does not execute in docker-compose?

copy iconCopydownload iconDownload
services:
  backend:
    environment:
      - PYTHONUNBUFFERED=1
    build:
      context: .
      dockerfile: backend.Dockerfile
services:
  backend:
    tty: true
-----------------------
services:
  backend:
    environment:
      - PYTHONUNBUFFERED=1
    build:
      context: .
      dockerfile: backend.Dockerfile
services:
  backend:
    tty: true

How to run a code just before django restarts?

copy iconCopydownload iconDownload
from django.dispatch import receiver
from django.utils.autoreload import file_changed

@receiver(file_changed)
def on_file_changed(sender, **kwargs):
    print("Custom file changed...")
    return True  # returning a truthy value prevents the reload.

cant join chat from a file (pyrogram)

copy iconCopydownload iconDownload
with app:
    for line in links.readlines():
            app.join_chat(line.rstrip()) # pass line to method

asyncio not working on Google Cloud Functions

copy iconCopydownload iconDownload
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

submit a data in a python script when it run by node js

copy iconCopydownload iconDownload
from pyrogram import Client
from pyrogram.raw import functions
import sys # we need the sys module to access these arguments I'm talking about

phone_number = sys.argv[1] # the phone number will be the first (and only, I'm assuming) argument. You can pass multiple arguments, and access them with `sys.argv[2]`, `sys.argv[3]`...etc.
api_id = someNumber
api_hash = "someHash"

with Client("my_account", api_id, api_hash, phone_number=phone_number) as app: # pass the phone number to Client
    print('Bot is online...')
if(command == 'run cli'){
     var spawn = require("child_process").spawn;
     var process = spawn('python', ["python/hello.py", "PHONE NUMBER GOES HERE"]);
     process.stdout.on('data', function(data) {
           console.log(data.toString());
     });
}
-----------------------
from pyrogram import Client
from pyrogram.raw import functions
import sys # we need the sys module to access these arguments I'm talking about

phone_number = sys.argv[1] # the phone number will be the first (and only, I'm assuming) argument. You can pass multiple arguments, and access them with `sys.argv[2]`, `sys.argv[3]`...etc.
api_id = someNumber
api_hash = "someHash"

with Client("my_account", api_id, api_hash, phone_number=phone_number) as app: # pass the phone number to Client
    print('Bot is online...')
if(command == 'run cli'){
     var spawn = require("child_process").spawn;
     var process = spawn('python', ["python/hello.py", "PHONE NUMBER GOES HERE"]);
     process.stdout.on('data', function(data) {
           console.log(data.toString());
     });
}

Community Discussions

Trending Discussions on pyrogram
  • How to get caption from Telegramm message(Pyrogram)
  • My telegram userbot can forward a message in private but not in a supergroup
  • Monkey Patching in Python using super.__init__
  • Pyrogram: The provided reply markup for the game is empty (caused by "messages.SendMedia")
  • ytmusicapi: JSON is not serializable in ytmusic.search
  • Dont send message with inlinekeyboard pyrogram
  • How to upload instant playable video to telegram
  • Importing decorated functions from multiple files doesn't seem to work
  • Pyrogram: MTProto to read and copy telegram messages
  • Split message with media content and without Telegram pyrogram Bot
Trending Discussions on pyrogram

QUESTION

How to get caption from Telegramm message(Pyrogram)

Asked 2022-Mar-18 at 15:19

I'm newbie at Python. I want to parse certain dialog(contains only captions to pics) with Pyrogram. But if i use iter_history() methog it returns none if message contains pic+text.Like that.

import asyncio
from pyrogram import Client

app = Client("my_acc")
target = "dialog_example"  # "me" refers to your own chat (Saved Messages)

with app:
    for message in app.iter_history(target):
        print(message.text)

None

Process finished with exit code 0

ANSWER

Answered 2022-Mar-18 at 15:19

message.text is a message's text. If you want the caption of a message (or document rather), access message.caption.

Source https://stackoverflow.com/questions/71527461

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install pyrogram

You can download it from GitHub.
You can use pyrogram like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

If you'd like to support Pyrogram, you can consider:.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Reuse Pre-built Kits with pyrogram
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.