Turn Any Database Into an API in 5 Minutes
Directus wraps any SQL database (Postgres, MySQL, SQLite) with instant REST and GraphQL APIs. Open-source, self-hosted, free.
Setup (Docker)
docker compose up -d
# docker-compose.yml:
# directus: image: directus/directus
# ports: ["8055:8055"]
# environment:
# DB_CLIENT: sqlite3
# DB_FILENAME: /directus/database/data.db
# ADMIN_EMAIL: admin@example.com
# ADMIN_PASSWORD: password
REST API (Auto-Generated)
import requests
BASE = "http://localhost:8055"
# Login
def login(email, password):
r = requests.post(f"{BASE}/auth/login",
json={"email": email, "password": password})
return r.json()["data"]["access_token"]
token = login("admin@example.com", "password")
headers = {"Authorization": f"Bearer {token}"}
# List items from any collection
def get_items(collection, limit=10):
r = requests.get(f"{BASE}/items/{collection}",
headers=headers, params={"limit": limit})
return r.json()["data"]
# Create item
def create_item(collection, data):
r = requests.post(f"{BASE}/items/{collection}",
headers=headers, json=data)
return r.json()["data"]
posts = get_items("posts")
create_item("posts", {"title": "New Post", "content": "Hello"})
GraphQL (Also Auto-Generated)
query {
posts(limit: 10, sort: ["-date_created"]) {
id
title
content
author { first_name last_name }
}
}
Why Directus
- Works with existing databases (no migration needed)
- Admin dashboard included
- File management built-in
- Roles and permissions
- Webhooks and flows
- Open-source (GPLv3)
Directus vs Alternatives
| Feature | Directus | Strapi | Hasura |
|---|---|---|---|
| Database | Any SQL | Postgres/MySQL | Postgres |
| API type | REST + GraphQL | REST + GraphQL | GraphQL |
| Existing DB | Yes | No | Yes |
| Admin UI | Yes | Yes | Yes |
| Self-hosted | Free | Free | Free |
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Need data from the web without writing scrapers? Check my *Apify actors** — ready-made scrapers for HN, Reddit, LinkedIn, and 75+ more sites. Or email: spinov001@gmail.com\n\n---\n\n*Need data from the web without writing scrapers? Check my *Apify actors** — ready-made scrapers for HN, Reddit, LinkedIn, and 75+ more sites. Or email: spinov001@gmail.com*
Top comments (0)