Build the future of communications.
Start building for free

Python posts

  • By August Allard
    PythonでHTTPリクエストを送信する5つの方法 PythonでHTTPリクエストを送信する5つの方法

    この記事はAugust Allardこちらで公開した記事(英語)を日本語化したものです。

    ソフトウェア開発では、同じ結果を得るための方法が複数あることがよくあります。これは、サードパーティーのソフトウェアパッケージを評価する際にも同じことが言えます。例えば、Pythonのエコシステムでは、HTTP リクエストの送信に関連するパッケージがいくつもあります。開発者はどれを使えばいいのでしょうか?

    この実験ベースのチュートリアルでは、Pythonの最も人気のあるリクエスト関連パッケージを5つご紹介します。各パッケージの簡単なGETリクエストを作成する方法と簡単なコードスニペットを例示します。NASAのAstronomy Photo of the Day API(以降「APOD」と短縮)を使って、Webブラウザで宇宙の写真を表示させます。

    本稿の目標は、各パッケージのすべての機能を細かく比較対照するのではなく、様々なPythonパッケージを使って簡単なGETリクエストを素早く構成することです。もし非同期リクエストがあなたのユースケースにより適しているなら、Twilioブログの「aiohttpとasyncioを使用したPythonの非同期HTTPリクエスト」を参照してください。

    必要事項

    NASAのデモ用APIキーを取得する

    https://api.nasa.gov/に移動します。認証セクションに、NASAデータセットを検索するために固有のAPIキーが必要ないことが記載されています。もしA …

    Read More
  • By Miguel Grinberg
    Erstelle einen WhatsApp-Chatbot mit Python Build a WhatsApp Chatbot with Python, Flask and Twilio

    Ein Chatbot ist eine Softwareanwendung, die ein Gespräch mit einem menschlichen Nutzer in geschriebener oder gesprochener Sprache führen kann. Der Grad der „Intelligenz“ von Chatbots kann sehr unterschiedlich sein. Während einige Chatbots ein eher einfaches Sprachverständnis zeigen, setzen andere hochkomplexe Algorithmen künstlicher Intelligenz (KI) und maschinelles Lernen (ML) ein, um ein nahezu menschliches Konversationsniveau zu erreichen.

    In diesem Tutorial zeige ich Ihnen, wie einfach Sie einen Chatbot für WhatsApp mit der Twilio-API für WhatsApp und dem Flask-Framework für Python erstellen können. Unten sehen Sie ein Beispiel für eine Interaktion, die ich mit diesem Chatbot hatte:

    WhatsApp chatbot demo session

    Anforderungen für das Tutorial zum WhatsApp-Chatbot

    Für dieses Tutorial benötigen Sie Folgendes:

    • Python 3.6 oder höher. Wenn Ihr Betriebssystem keinen Python-Interpreter bereitstellt, können Sie unter python.org einen Installer herunterladen.
    • Flask. Wir erstellen eine Webanwendung, die damit auf eingehende WhatsApp-Nachrichten reagiert.
    • ngrok. Dieses praktische Dienstprogramm verwenden wir, um die Flask-Anwendung auf Ihrem System mit …
    Read More
  • By Miguel Grinberg
    Serverless Twilio Webhooks on AWS with Lambda Function URLs Serverless Twilio Webhooks on AWS with Lambda Function URLs

    Serverless platforms are ideal for the deployment of webhooks such as those used by Twilio services, as they provide flexibility and scalability without the complications involved in hosting on your own infrastructure.

    In this tutorial you are going to learn how to create a Twilio SMS webhook written in Python using AWS Lambda, with its brand new function URLs feature.

    Requirements

    To work on this tutorial you will need the following items:

    • A Python 3 interpreter compatible with AWS Lambda (as of April 2022, Python 3.6, 3.7, 3.8 or 3.9). If your operating system does not provide a Python interpreter, you can go to python.org to download an installer.
    • Node.js installed on your computer. You can download a Node.js installer from the Node.js website.
    • A Twilio account. If you are new to Twilio click here to create a free account now and receive $10 credit when you upgrade …
    Read More
  • By Mia Adjei
    Host Video Office Hours with SMS Notifications using Python and Twilio Host Video Office Hours with SMS Notifications using Python and Twilio

    When you think of "office hours", what comes to mind? Perhaps you imagine a professor who has set aside time for students to stop by their office to ask for advice or receive guidance. Or maybe you imagine a business leader who creates space on their calendar for colleagues and direct reports to ask questions or share their ideas.

    With the rise of virtual and hybrid environments, many people have taken their office hours online, and video chat provides a great way to have face-to-face conversations without needing to be in the same physical location.

    In this tutorial, you will learn how to build a virtual office hours application that allows you to create a new, named video room with a customized timeout window and receive an SMS notification when a participant joins the room. For this project, you will use Python and Flask, along with a bit of …

    Read More
  • By Sam Agnew
    Using Event Webhooks for Emails with Twilio SendGrid in Python Copy of C04 Blog Text.png

    When sending emails with Twilio SendGrid, sometimes you want to be able to keep track of the status of these emails, such as when a recipient opens the message or reports it as spam. This is made possible by the use of Event Webhooks. Let's walk through how to use Python and Flask to track the status of emails that you send.

    Prerequisites and dependencies

    Make sure you have the following before moving on:

    • Python 3 installed on your machine
    • A free SendGrid account
    • An email address to test out this project
    • A domain on which you will receive emails. For the purposes of this article, I’m going to use yourdomainhere.com. You will need to replace it with your own domain name.

    Here is a guide you can follow for setting up your development environment if you are going to be doing more web development with Python in …

    Read More
  • By Miguel Grinberg
    Transcribe your Phone Calls to Text in Real Time with Twilio and Vosk  Transcribe your Phone Calls to Text in Real Time with Twilio and Vosk

    In this tutorial, you are going to learn how to implement live transcription of phone calls to text. The phone calls will be routed through a Twilio phone number, and we will use the Media Streams API to stream the incoming audio to a small WebSocket server built using Python. Once in your server, the audio stream will be passed to Vosk, a lightweight open-source speech recognition engine that runs locally on your computer, with support for many languages.

    Live transcription of phone calls demonstration

    Requirements

    To work on this tutorial, you will need:

    Read More
  • By Matthew Setter
    Build Your Own Weather Station With PHP, Python and a Raspberry Pi Build your own weather station with PHP, Python and a Raspberry Pi

    Raspberry Pi, Arduino, BeagleBone, and similar technologies have had a revolutionary impact on so many people around the world.

    Because they provide the building blocks of computing for a very low price, anyone, from a school student to a retiree, with a little bit of time and effort, can build a device that perfectly scratches whatever itch they have. They no longer need to wait for a commercial organisation to build it.

    One such itch (at least one that I have) is to measure the current temperature and humidity throughout the rooms in my home. Sure, weather app's can tell you the current temperature and humidity, however, they can only do it for a wide geographical area.

    So, in this tutorial, you're going to learn how to create a small weather station with a Raspberry Pi, some PHP and Python code, and a temperature and humidity sensor — for …

    Read More
  • By Sam Agnew
    Mars Rover Emails with Python and Twilio SendGrid Copy of C01 Blog Text.png

    NASA has a bunch of awesome APIs which give you programmatic access to the wonders of space. I think the Mars Rover Photos API in particular is really amazing as you can use it to see what kind of pictures the Mars Curiosity rover has been taking.

    Let’s build an app using the Mars Rover API with Twilio SendGrid, Python, and Flask to make it so that we can send an email and receive back pictures from Mars.

    Prerequisites and dependencies

    Make sure you have the following before moving on:

    • Python 3 installed on your machine
    • A free SendGrid account
    • An email address to test out this project
    • A domain on which you will receive emails. For the purposes of this article, I’m going to use yourdomainhere.com. You will need to replace it with your own domain name.

    Here is a guide you can follow for setting …

    Read More
  • By Naomi Pentrel
    Use Twilio Video to Create a Dog Camera Dog Cam

    There are multiple apps and services out there that you can use as a dog cam. However, most of these apps and services require you to pay for new devices or a subscription (or both!). When I recently adopted a puppy, I used Twilio Video and an old phone to create my own free dog cam.

    In this blog post, I’ll show you how to build your own dog cam using:

    1. a Twilio account – sign up for free
    2. Python 3.x
    3. the micro web framework Flask
    4. the Twilio Python helper library
    5. ngrok - sign up for free
    6. An old phone or tablet

    Features

    For the Dog Cam, there were a few features I wanted:

    Free or low cost solution

    Existing dog cameras mostly require you to spend money on a subscription or new hardware. What I wanted was a free or low cost solution that can run on any internet-connected …

    Read More
  • By Sam Agnew
    PythonとBeautiful SoupでWebスクレイピングとHTML解析をする方法 PythonとBeautiful SoupでWebスクレイピングとHTML解析をする方法

    この記事はSam Agnewこちらで公開した記事(英語)を日本語化したものです。

    インターネットにはあまりに多くのデータがあふれています。しかし、これらのデータがREST APIの形式ではないと、プログラムによってアクセスすることは難しくなります。Beautiful SoupなどのPythonツールを使用すると、Webページから直接データをスクレイピングして解析し、プロジェクトやアプリケーションで使えるようになります。

    本稿では、インターネットからMIDIデータをスクレイピングする方法をご紹介します。過去のブログで、Magentaによるニューラルネットワークのトレーニングを使用してクラシックな任天堂ゲームミュージックを作成する方法をご紹介しました。この実装には、昔の任天堂ゲームのMIDIミュージックが必要になります。今回は、Beautiful Soupを使用して、ビデオゲーム音楽アーカイブからMIDIデータを取得する方法をご紹介します。

    プロジェクトの準備と依存パッケージの設定

    まず、最新バージョンのPython 3とpipがインストールされていることを確認してください。また、依存パッケージをインストールする前に、仮想環境を作成して有効にしてください。

    Webページからのデータ取得のHTTPリクエストを作成するRequestsライブラリと、HTMLを解析するBeautiful Soupをインストールする必要があります。

    仮想環境を有効にしたら、ターミナルで次のコマンドを実行します。

    pip install requests==2.22. …
    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.