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

Create Command Line Application With Golang

Creating a Command Line Application to Separate Files by Extension in Go If you have a folder with a large number of files and you want to organize them by file extension, you can create a command line application to do this automatically using Go. Go, also known as Golang, is a programming language developed by Google that is designed to be fast, statically-typed, and easy to learn. In this article, we’ll walk through the steps to create a Go program that separates files in a given folder into subfolders based on their extension. ...

December 20, 2022 · 5 min · 890 words

Create Website With Gatsby and Github Pages

GitHub Pages is a free service that allows you to host your website directly from a GitHub repository. It is a great platform for developers to showcase their portfolio, document their projects, or create a personal blog. In this article, we will walk through the steps of creating a static website using GitHub Pages and Gatsby, a popular static site generator. Install Gatsby First, you will need to install Gatsby by running the following command in your terminal: npm install -g gatsby-cli Create a new Gatsby project gatsby new my-website This will create a new directory called my-website with the necessary files and dependencies for your Gatsby project. ...

December 20, 2022 · 3 min · 434 words