# Python Humanize Module

The `humanize` library provides various common humanization utilities, like turning a number into a fuzzy human-readable duration ("3 minutes ago") or into a human-readable size or throughput.

## Installation

```bash
pip install humanize
```

## Importing the Module

```python
import humanize
import datetime
```

## Integers

### Comma Separation (`intcomma`)

Converts an integer to a string containing commas every three digits.

```python
print(humanize.intcomma(12345))     # 12,345
print(humanize.intcomma(123456789)) # 123,456,789
```

### Word Representation (`intword`)

Converts a large integer to a friendly text representation. Works best for numbers over a million.

```python
print(humanize.intword(12345591313)) # 12.3 billion
print(humanize.intword(1000000))     # 1.0 million
```

### AP Style Numbers (`apnumber`)

For numbers 1-9, returns the number spelled out. Otherwise, returns the number. This follows Associated Press style.

```python
print(humanize.apnumber(4))  # four
print(humanize.apnumber(41)) # 41
```

## Date and Time

### Natural Time (`naturaltime`)

Returns a fuzzy time span relative to now.

```python
import datetime

now = datetime.datetime.now()
ago = now - datetime.timedelta(hours=24)
print(humanize.naturaltime(ago)) # a day ago

future = now + datetime.timedelta(seconds=30)
print(humanize.naturaltime(future)) # 30 seconds from now
```

### Natural Delta (`naturaldelta`)

Formats a timedelta object into a human-readable string.

```python
delta = datetime.timedelta(seconds=1001)
print(humanize.naturaldelta(delta)) # 16 minutes
```

## File Sizes (`naturalsize`)

Formats a number of bytes into a human-readable file size (e.g., '13 KB', '4.1 MB').

```python
print(humanize.naturalsize(1024))       # 1.0 kB
print(humanize.naturalsize(1024, binary=True)) # 1.0 KiB
print(humanize.naturalsize(1000000))    # 1.0 MB
```

## Scientific Notation (`scientific`)

```python
print(humanize.scientific(0.0000000000003)) # 3.0 x 10⁻¹³
print(humanize.scientific(10000))           # 1.0 x 10⁴
```

[[programming/python/python]]