Understand Async Await in Python

Async/await is a powerful programming construct that allows you to write asynchronous code in a synchronous-like style. It was introduced in Python 3.5 as part of the asyncio module and has become a popular choice for writing concurrent and parallel code in Python. In this post, we’ll take a look at what async/await is and how it works, as well as some of the benefits and drawbacks of using it. We’ll also see some examples of how to use async/await in Python to write efficient and scalable code. ...

January 1, 2023 · 5 min · 1030 words

Create a Telegram Bot With Rust

Install Rust Before you can start writing Rust code, you’ll need to install the Rust programming language on your computer. You can do this by following the instructions on the Rust website (https://www.rust-lang.org/tools/install). Set up a new Rust project Once you have Rust installed, you’ll need to create a new Rust project using the cargo command-line tool. Open a terminal and navigate to the directory where you want to store your project, then run the following command: cargo new telegram-bot –bin. This will create a new Rust project called “telegram-bot” with a binary crate (executable). ...

December 31, 2022 · 4 min · 733 words

Create a Webserver With Fastapi and Uvicorn

FastAPI is a modern, fast, web framework for building APIs with Python 3.7 and above. It is built on top of Starlette, a lightweight ASGI framework, and uses the uvicorn ASGI server. Here is an example of how to create a web server with FastAPI and uvicorn: Install FastAPI and uvicorn using pip: pip install fastapi uvicorn Create a file called main.py and import FastAPI: from fastapi import FastAPI app = FastAPI() Define a function that will be the endpoint for your API. This function should have a request parameter that specifies the HTTP request and a response parameter that specifies the HTTP response. You can use the @app.get decorator to define a function as a GET endpoint: @app.get("/") def read_root(request, response): response.status_code = 200 return {"Hello": "World"} Run the web server using uvicorn: if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000) This will start the web server on the specified host and port (in this case, 0.0.0.0 and 8000). You can then access the endpoint at http://0.0.0.0:8000/. ...

December 30, 2022 · 1 min · 186 words

What Does Yield Keyword Do in Python

The keyword “yield” is a important part of the Python programming language, and it can be used in a number of different ways. In this article, we’ll take a closer look at what the yield keyword does in Python, and how it can be used to create more efficient and powerful programs. The primary use of the yield keyword is to create a generator function. A generator function is a special type of function that produces a sequence of values, one at a time, when it is called. Unlike a regular function, which executes all of its code and returns a single value, a generator function can be paused at any point and resumed later, allowing it to produce a potentially infinite sequence of values. ...

December 29, 2022 · 3 min · 440 words

Use Protobuf With Golang

Protocol Buffers (Protobuf) is a language- and platform-neutral data serialization format developed by Google. It allows you to define data structures in a .proto file and then use code generation tools to generate code in various languages for working with those data structures. To use Protobuf with Go, you’ll need to do the following: Install the Protobuf compiler (protoc) and the Go Protobuf plugin: # Install protoc wget https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip unzip protoc-3.14.0-linux-x86_64.zip -d protoc3 sudo mv protoc3/bin/* /usr/local/bin/ # Install the Go Protobuf plugin go get -u github.com/golang/protobuf/protoc-gen-go Define your data structures in a .proto file. For example: ...

December 27, 2022 · 2 min · 425 words