10 Python Libraries that Every Beginner should Know
Tags: python, programming, codenewbie, beginners
Published: 2022-09-23 23:57:21

As we all know python has numerous in-built libraries that can be used to do different computations without writing the specific code again from the scratch. The new libraries are continuously developed by authors across the globe to enhance python language usage.

## 10 Main Python Libraries that every coder must know

- import datetime 

This can be considered as one of the main libraries that is often used to get all values related to the current date, time, and year. Let’s us discuss how can we use it

```python
import datetime

var1 = datetime.datetime.now()

print(var1)
2021-06-26 09:08:37.165221
```

Here is one more example of how to get [yesterday date in Python](https://devhubby.com/thread/how-to-get-yesterday-date-in-python).

- import os 

Another important library used to interact with the Operating System. It is used to find the path of the files or directories or read or write files from the system.

```python
import os

var1 = os.getcwd()

print(var1)
C:\Users\Admin\AppData\Local\Programs\Python\Python37-32
```

- import random

It is used to select random character or string  from a collection such as a list, tuple, dictionary

```python
import random

listt = ['apple','mango','banana','orange']

print(random.choice(listt))
```

Here is one more example of how to generate [random passwords](https://devhubby.com/thread/how-to-generate-random-passwords-in-python) in python.

- import requests

This library is used to sent HTTP request externally on a server

```python
import requests

url = "https://www.google.com"

response = requests.get(url)

print(response.status)
```

Here is how to [parse a dynamic web page](https://devhubby.com/thread/how-to-parse-a-dynamic-web-page-in-python) in Python?

- import pandas

It is often used to create or read from the data frame or do operations on dataframes
```python
import pandas as pd
```

Here you can find how to [install pandas](https://devhubby.com/thread/how-to-install-pandas-in-python) in python?

- import BeautifulSoup

Beautiful Soup is a library that makes it easy to scrape information from web pages. It sits atop an HTML or XML parser, providing Pythonic idioms for iterating, searching, and modifying the parse tree.

```python
from bs4 import BeautifulSoup

url = "https://www.google.com"

response= requests.get(url)

soup = BeautifulSoup(response.txt)

print(soup)
```

- import JSON

Python has a built-in package called json, which can be used to work with JSON data

```python
import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])
```

Here you can find one more example of how to convert [string to JSON](https://devhubby.com/thread/how-to-convert-string-to-json-in-python) in python.

- import pytest

The pytest the framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries

- import CSV

```python
import csv
with open('eggs.csv', 'w', newline='') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=' ',
                            quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
```

Here is one more example of how to [read a CSV files](https://devhubby.com/thread/how-to-read-csv-file-in-python) in Python.

- import math

This module provides access to the mathematical functions defined by the C standard.

```python
#Import math Library
import math

#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
```