# 🔗 linksnap

**Snap a quick status check on any URL or list of URLs.**

linksnap is a fast, zero-dependency Python library for checking whether URLs
are alive, dead, or redirecting — with response times, SSL validation,
file scanning, and CSV/JSON export built in.

---

## Install

pip install linksnap

---

## Quick start

import linksnap

linksnap.snap([
    "https://google.com",
    "https://github.com",
    "https://thispagedoesnotexist99.com",
    "https://httpstat.us/404",
])

Output:

🔗 linksnap — checking 4 URL(s)...

  ✅ ALIVE (200) [143ms] 🔒     https://google.com
  ✅ ALIVE (200) [201ms] 🔒     https://github.com
  ❌ DEAD                       https://thispagedoesnotexist99.com
  ❌ DEAD (404) [89ms]          https://httpstat.us/404

  📊 4 checked  |  2 alive  |  0 redirected  |  2 dead  |  0 errors

---

## Features

### ✅ Check a list of URLs
results = linksnap.check([
    "https://google.com",
    "https://github.com",
])

for r in results:
    print(r["url"], r["status"], r["code"], r["response_ms"])

Each result is a dict with:
  - url          the original URL
  - status       ALIVE, DEAD, REDIRECT, or ERROR
  - code         HTTP status code (or None)
  - redirect     final URL if redirected (or None)
  - response_ms  response time in milliseconds (or None)
  - ssl          True (valid cert), False (invalid cert), None (not HTTPS)

---

### 🌐 Scan a webpage for broken links
linksnap.scan_page("https://example.com")

Fetches the page, extracts every link, and checks them all at once.

---

### 📂 Check links from a file
linksnap.from_file("urls.txt")   # one URL per line
linksnap.from_file("links.csv")  # scans all cells
linksnap.from_file("page.html")  # extracts all href links

---

### 💾 Export results
results = linksnap.check(["https://google.com", "https://github.com"])

linksnap.to_json(results, "results.json")
linksnap.to_csv(results, "results.csv")

---

### ⚙️ Options

All functions support these optional arguments:

  workers=10   number of concurrent threads (increase for large lists)
  retries=1    how many times to retry a dead link before giving up

linksnap.snap(urls, workers=20, retries=2)

---

## Why linksnap?

- ⚡ Fast      — checks URLs concurrently using threads
- 📦 Zero deps — pure Python stdlib, nothing to install
- 🔒 SSL check — flags invalid or missing HTTPS certificates
- ⏱  Timing    — measures response time for every URL
- 🔁 Retries   — retries dead links before marking them as dead
- 📂 Files     — reads from .txt, .csv, and .html files
- 💾 Export    — saves results to JSON or CSV

---

## License

MIT