{"id":15432973,"url":"https://github.com/simonw/asgi-log-to-sqlite","last_synced_at":"2025-04-19T17:52:12.156Z","repository":{"id":57411797,"uuid":"228469685","full_name":"simonw/asgi-log-to-sqlite","owner":"simonw","description":"ASGI middleware for logging traffic to a SQLite database","archived":false,"fork":false,"pushed_at":"2020-02-24T20:15:50.000Z","size":12,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T07:53:37.144Z","etag":null,"topics":["asgi","datasette-io","logging","sqlite"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-16T20:27:04.000Z","updated_at":"2021-11-06T21:19:28.000Z","dependencies_parsed_at":"2022-08-27T17:10:36.037Z","dependency_job_id":null,"html_url":"https://github.com/simonw/asgi-log-to-sqlite","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fasgi-log-to-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fasgi-log-to-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fasgi-log-to-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fasgi-log-to-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/asgi-log-to-sqlite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249753089,"owners_count":21320664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","datasette-io","logging","sqlite"],"created_at":"2024-10-01T18:29:53.624Z","updated_at":"2025-04-19T17:52:12.133Z","avatar_url":"https://github.com/simonw.png","language":"Python","readme":"# asgi-log-to-sqlite\n\n[![PyPI](https://img.shields.io/pypi/v/asgi-log-to-sqlite.svg)](https://pypi.org/project/asgi-log-to-sqlite/)\n[![CircleCI](https://circleci.com/gh/simonw/asgi-log-to-sqlite.svg?style=svg)](https://circleci.com/gh/simonw/asgi-log-to-sqlite)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/asgi-log-to-sqlite/blob/master/LICENSE)\n\nASGI middleware for logging traffic to a SQLite database\n\nSee [Logging to SQLite using ASGI middleware](https://simonwillison.net/2019/Dec/16/logging-sqlite-asgi-middleware/) for background on this project.\n\n## Installation\n\n    pip install asgi-log-to-sqlite\n\n## Usage\n\n```python\nfrom asgi_log_to_sqlite import AsgiLogToSqlite\nfrom my_asgi_app import app\n\n\napp = AsgiLogToSqlite(app, \"/tmp/log.db\")\n```\n\nRequests to your ASGI app will now be logged to the SQLite database file at `/tmp/log.db`.\n\n## Schema\n\nThe database used to log requests has one key table - `requests` - and 6 lookup tables: `paths`, `user_agents`, `referers`, `accept_languages`, `content_types` and `query_strings`.\n\nThe full schema is as follows:\n\n```sql\nCREATE TABLE [paths] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_paths_name\n                ON paths (name);\nCREATE TABLE [user_agents] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_user_agents_name\n                ON user_agents (name);\nCREATE TABLE [referers] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_referers_name\n                ON referers (name);\nCREATE TABLE [accept_languages] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_accept_languages_name\n                ON accept_languages (name);\nCREATE TABLE [content_types] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_content_types_name\n                ON content_types (name);\nCREATE TABLE [query_strings] (\n   [id] INTEGER PRIMARY KEY,\n   [name] TEXT\n);\nCREATE UNIQUE INDEX idx_query_strings_name\n                ON query_strings (name);\nCREATE TABLE [requests] (\n   [start] FLOAT,\n   [method] TEXT,\n   [path] INTEGER REFERENCES [paths]([id]),\n   [query_string] INTEGER REFERENCES [query_strings]([id]),\n   [user_agent] INTEGER REFERENCES [user_agents]([id]),\n   [referer] INTEGER REFERENCES [referers]([id]),\n   [accept_language] INTEGER REFERENCES [accept_languages]([id]),\n   [http_status] INTEGER,\n   [content_type] INTEGER REFERENCES [content_types]([id]),\n   [client_ip] TEXT,\n   [duration] FLOAT,\n   [body_size] INTEGER\n);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fasgi-log-to-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fasgi-log-to-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fasgi-log-to-sqlite/lists"}