Posts Related To Python (25)

Object-oriented Programming In Python

Object-oriented Programming In Python

Object-oriented programming, as the name suggests, is a method where related properties and behaviors are bundled into individual objects. These objects are instances of a class that has generic attributes and methods used to define something. Think of a car, it has wheels and can move. The car is generic and can be used to define a Bentley or a Benz. In this article, you will learn how to create and use objects in Python.

Unit Testing in Python

Unit Testing in Python

Unit testing is a development approach that looks at the smallest pieces of code, called units, in a software application that are tested for correct operations. When a unit is tested, you can verify that the code tested works as intended. In this article, you will learn how to implement unit testing on a Python script.

Download and Encrypt PDFs in Flask

Download and Encrypt PDFs in Flask

PDF documents are not editable by nature. They are the sole read-only file format that can’t be altered without leaving a footprint. This allows the effective tracking of changes in respective documents. Encryption can be enabled in the document to protect it wherever it goes, independent of storage or transport. As complex as this entire document creation and encryption process seems to be, Flask allows for the integration of this feature in an application.

Visualize Data In Your Flask App Using ChartJS

Visualize Data In Your Flask App Using ChartJS

Data visualization is the graphic representation of information. This could be in the form of a chart, diagram, map, or picture. In the world of Big Data, data visualization tools and technologies are essential for analyzing large datasets and making data-driven decisions.

ChartJs is a free and open-source JavaScript library used to make HTML-based charts. It is powerful enough to reproduce very responsive charts and plots. You can use it to plot static and constantly changing data.

Upload Files To A Database In Your Flask App

Upload Files To A Database In Your Flask App

You probably are already familiar with how to update a table in your flask database, for example, you know how to add a new user who has just registered for an account in your application. This user may want to update their profile image, or simply attach a file needed in a submission. How can you handle this need in your flask application?

Welcome to My Blog

Welcome to My Blog

Hello,

I am glad that you have stopped by. This is my personal blog engine. I decided to put it together for two broad reasons:

  • To share what I know thus far
  • To show some of the interesting things I have been up to



I hope that you find something that interests you. If you enjoy whatever you find, I will be glad to hear from you in the comments sections.

Gitau Harrison

Install And Configure Elasticsearch In Your Linux Server

Install And Configure Elasticsearch In Your Linux Server

If you are personally hosting your Python-powered app, you will have to contend with configuring Elasticsearch manually to ensure it works in production. As with any other deployment on a Linux server, the process of configuring yet another service can be intimidating. In this article, you will learn how to get your Elasticsearch service to work on Linode.

Implement Search Feature In Your Flask App Using Elasticsearch

Implement Search Feature In Your Flask App Using Elasticsearch

The search feature can dramatically improve a user's experience while interacting with an application. A simple form can be added to a web page or the navigation bar to allow a user to quickly retrieve desired results. In this article, you will learn how to implement a very generic approach to building a search functionality such that you can easily switch from one search engine to another.

Install Elasticsearch In Ubuntu 20.04 Localhost

Install Elasticsearch In Ubuntu 20.04 Localhost

If you are looking at utilizing Elasticsearch, the free and open-source search and analytics tool, you have to familiarize yourself with the technical setup details. In this article, you will learn how to download, install and start the Elasticsearch service. You will also briefly learn how to use sample JSON data to ingest and index search queries in your Flask app.

Application Programming Interfaces (APIs) In Flask

Application Programming Interfaces (APIs) In Flask

An Application Programming Interface is a low-level entry point into an application that a client can use to work with the application in a more direct way than through the traditional web browser workflow. Think of it as an intermediary layer that processes data between systems, through which a company can share its application's data and functionality with external third-party developers, partners, or even internal departments.

In this article, you will learn the basic principles that help guide the development of an API. There are several types of APIs. We will examine the most popular API among them all, the REST API.

Implement An API Blueprint In Flask

Implement An API Blueprint In Flask

A blueprint is a logical structure that represents a subset of the application. We can write a blueprint in a separate Python package that encapsulates the elements related to that specific feature of the application, in this case, an API. The essence of using blueprints in your Flask app is to allow for the adaptation of the application as it becomes larger or as the application's needs change.

Representation Of Resources In Flask API

Representation Of Resources In Flask API

Before building any API, it is important to decide what the representation of its resources is going to be. Both the server and the client must agree on a format to represent a resource. Most modern APIs use the JavaScript Object Notation (JSON) format to build resource representations, though an API can support multiple representation formats when properly defined in their content negotiation options.

Handling Errors In Flask API

Handling Errors In Flask API

What happens when an error occurs in a Flask application? We would create custom HTML error pages such as 404.html or 500.html that display more user-friendly content. Flask would return these pages instead of a rather scary and oftentimes too revealing stack trace.

In the context of APIs, we would need a "machine-friendly" type of error, something that the client application would easily interpret.

Unique Resource Identifiers In Flask API

Unique Resource Identifiers In Flask API

A URI (Uniform Resource Identifier) is a string of characters that identifies a resource on the Internet. They are achieved by assigning a unique URL to each resource. For example, if a database has a user identified by the username "muthoni", her unique URL would be something such as /users/muthoni where muthoni is the identifier assigned to the user in the database. Such an endpoint can be reasonably implemented in an API.

API Authentication In Flask

API Authentication In Flask

In a typical web application, there are certain web pages that require a user to login in order to access their content. Such pages require a client to identify, authenticate, and authorize a user in an effort to preserve their integrity. Traditionally, an anonymous user will be redirected to an HTML login page from where they will be verified.

It is also possible to achieve the same level of security when it comes to accessing an application's endpoints. Because there is no concept of HTML or login pages in an API, the server needs to return an appropriate response to the client to inform a user that they need to supply valid credentials.

API-friendly Error Messages In Flask

API-friendly Error Messages In Flask

We can go to extra lengths to provide custom error-handling mechanisms in an API, but there are some errors that would bypass these efforts and instead return HTML responses.

The HTTP protocol supports a mechanism by which the client and the server can agree on the best format for a response, called content negotiation. The client needs to send an Accept header with the request, indicating the format preferences. The server then looks at the list and responds using the best format it supports from the list offered by the client.

API Testing Using Postman

API Testing Using Postman

The HTTPie package is a fantastic command-line tool that can be used to test endpoints designed for testing, debugging, and generally interacting with APIs & HTTP servers. Another popular API-testing tool is Postman. It offers both a web and desktop client for creating, testing, sharing, and documenting APIs. While using Postman, for testing purposes, one doesn't need to write any HTTP client network code. Instead, we build test suites called collections and let Postman interact with the API.

Email Support In Flask

Email Support In Flask

Sending emails is a vital part of most web applications. There are many instances that may require the sending of emails in your application. For example, when a new user registers for an account, you may want to notify them of this action through the email they have registered with. Certain cronjobs may require the automatic sending of emails to an application's users at regular intervals. When it comes to user authentication, an application can also incorporate the ability to request a password reset.