• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A SQLite extension for making HTTP requests purely in SQL

sqlite-http

A SQLite extension for making HTTP requests purely in SQL.

  • Create GET, POST, and other HTTP requests, like curl, wget, and fetch
  • Download response bodies, header, status codes, timing info
  • Set rate limits, timeouts

Usage

.load ./http0
select http_get_body('https://text.npr.org/');
/*
<!DOCTYPE html>
<html lang="en">
<head>
  <title>NPR : National Public Radio</title>
  ....
*/

Query for all custom headers in an endpoint.

select name, value
from http_headers_each(
  http_get_headers('https://api.github.com/')
)
where name like 'X-%';
/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          name          β”‚               value                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ X-Ratelimit-Limit      β”‚ 60                                 β”‚
β”‚ X-Ratelimit-Used       β”‚ 8                                  β”‚
β”‚ X-Content-Type-Options β”‚ nosniff                            β”‚
β”‚ X-Github-Media-Type    β”‚ github.v3; format=json             β”‚
β”‚ X-Github-Request-Id    β”‚ CCCA:5FDF:1014BC2:10965F9:62F3DE4E β”‚
β”‚ X-Ratelimit-Remaining  β”‚ 52                                 β”‚
β”‚ X-Ratelimit-Resource   β”‚ core                               β”‚
β”‚ X-Frame-Options        β”‚ deny                               β”‚
β”‚ X-Ratelimit-Reset      β”‚ 1660152798                         β”‚
β”‚ X-Xss-Protection       β”‚ 0                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

Scrape data from a JSON endpoint.

select http_get_body('https://api.github.com/repos/sqlite/sqlite')
  ->> '$.description' as description;
/*
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  description                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Official Git mirror of the SQLite source tree β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
*/

Pass in specific headers in a request.

select
  value
from json_each(
  http_get_body(
    'https://api.github.com/issues',
    http_headers(
      'Authorization', 'token ghp_16C7e42F292c6912E7710c8'
    )
  )
);

Documentation

See docs.md for a full API reference.

Installing

Language Install
Python pip install sqlite-http PyPI
Datasette datasette install datasette-sqlite-http Datasette
Node.js npm install sqlite-http npm
Deno deno.land/x/sqlite_http deno.land/x release
Ruby gem install sqlite-http Gem
Github Release GitHub tag (latest SemVer pre-release)

The Releases page contains pre-built binaries for Linux amd64, MacOS amd64 (no arm), and Windows.

As a loadable extension

If you want to use sqlite-http as a Runtime-loadable extension, Download the http0.dylib (for MacOS), http0.so (Linux), or http0.dll (Windows) file from a release and load it into your SQLite environment.

Note: The 0 in the filename (http0.dylib/ http0.so/http0.dll) denotes the major version of sqlite-http. Currently sqlite-http is pre v1, so expect breaking changes in future versions.

For example, if you are using the SQLite CLI, you can load the library like so:

.load ./http0
select http_version();
-- v0.0.1

Or in Python, using the builtin sqlite3 module:

import sqlite3

con = sqlite3.connect(":memory:")

con.enable_load_extension(True)
con.load_extension("./http0")

print(con.execute("select http_version()").fetchone())
# ('v0.0.1',)

Or in Node.js using better-sqlite3:

const Database = require("better-sqlite3");
const db = new Database(":memory:");

db.loadExtension("./http0");

console.log(db.prepare("select http_version()").get());
// { 'http_version()': 'v0.0.1' }

Or with Datasette, with the "no network" option to limit DDoS attacks:

datasette data.db --load-extension ./http0-no-net

See also

  • sqlite-html, for parsing and querying HTML using CSS selectors in SQLite (pairs great with this tool)
  • pgsql-http, a similar yet very different HTTP library for POstgreSQL (didn't know about this before I started this, but interestingly enough came up with a very similar API)
  • riyaz-ali/sqlite, the brilliant Go library that this library depends on
  • nalgeon/sqlean, several pre-compiled handy SQLite functions, in C

More Repositories

1

sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
C++
482
star
2

sqlite-lines

A SQLite extension for reading large files line-by-line (NDJSON, logs, txt, etc.)
C
371
star
3

dataflow

An experimental self-hosted Observable notebook editor, with support for FileAttachments, Secrets, custom standard libraries, and more!
JavaScript
346
star
4

sqlite-html

A SQLite extension for querying, manipulating, and creating HTML elements.
Go
341
star
5

sqlite-loadable-rs

A framework for writing fast and performant SQLite extensions in Rust
Rust
246
star
6

sqlite-regex

A fast regular expression SQLite extension, written in Rust
Rust
120
star
7

unofficial-observablehq-compiler

An unofficial compiler for Observable notebook syntax
JavaScript
99
star
8

sqlite-xsv

the fastest CSV SQLite extension, written in Rust
Rust
88
star
9

sqlite-ulid

A SQLite extension for generating and working with ULIDs
Python
79
star
10

streamlit-observable

Embed Observable notebooks into Streamlit apps!
TypeScript
79
star
11

observable-prerender

Pre-render Observable notebooks for automation
JavaScript
55
star
12

sqlite-ecosystem

An overview of all my SQLite extensions, and a roadmap for future extensions and tooling!
TypeScript
53
star
13

sqlite-jsonschema

A SQLite extension for validating JSON objects with JSON Schema
TypeScript
25
star
14

sqlite-geo

A work-in-progress SQLite extension for geospatial data
Rust
24
star
15

sqlite-url

A SQLite extension for parsing, generating, and querying URLs and query strings
C
22
star
16

sqlite-path

A SQLite extension for parsing, generating, and querying paths
C
19
star
17

sqlite-fastrand

A SQLite extension for quickly generating random numbers, booleans, characters, and blobs
Rust
16
star
18

sqlite-vector

A SQLite extension for working with float and binary vectors. Work in progress!
C++
14
star
19

atom-observable

Render Observable notebooks in Atom!
JavaScript
11
star
20

oak

A CLI tool for reproducible, customizable data workflows.
TypeScript
11
star
21

sqlite-base64

Python
8
star
22

sqlite-python

Rust
7
star
23

sqlite-md

A SQLite extension for parsing, querying, and generating HTML from Markdown documents.
Rust
6
star
24

sqlite-parquet

Rust
6
star
25

churro

Access your terminal in an Observable notebook!
JavaScript
5
star
26

sqlite-image

Rust
4
star
27

sqlite-hello

Elixir
4
star
28

TritonFind

A Facebook Messenger Bot that assists UC San Diego students get their lost items back.
JavaScript
4
star
29

sqlite.org-extensions

C
4
star
30

NeverAgainColleges

HTML
3
star
31

sqlite-xml

Rust
3
star
32

ondemand-whisper-fly

Python
3
star
33

streamlit-observable-showcase

An example Streamlit app showcasing the features of the streamlit-observable package.
Python
3
star
34

os-club-constitution

Constitution for a (future) open source club at UCSD
3
star
35

UCSD-Professional-Website-Maker

Make a very professional website for your acsweb.ucsd.edu/~ account
HTML
3
star
36

sqlite-pdf

Rust
2
star
37

unofficial-observable-notebook-react

JavaScript
2
star
38

disney-plus-analysis

Python
2
star
39

har-to-sqlite

TypeScript
2
star
40

shl

A tagged template literal for shell commands! (Work in Progress)
JavaScript
2
star
41

upload-spm

TypeScript
2
star
42

sqlite-jiff

Rust
2
star
43

SDHacks-2016---Trivents-Messenger-Bot

Messenger Bot our team made at SDHacks 2016, Winner of the DocuSign Sponsor Prize
JavaScript
1
star
44

sqlite-versions

TypeScript
1
star
45

sqlite-fake

Rust
1
star
46

sqlite-semver

Rust
1
star
47

sqlite-rembed

Rust
1
star
48

native-lands-colleges

JavaScript
1
star
49

isthegovernmentshutdown.info

HTML
1
star
50

TritonPal-Chrome-Extension

A Chrome Extension that will help all UC San Diego students.
JavaScript
1
star