groveco / django-sql-explorer
- вторник, 1 ноября 2016 г. в 03:15:35
Python
Easily share data across your company via SQL queries. From Grove Collab.
SQL Explorer aims to make the flow of data between people fast, simple, and confusion-free.
Quickly write and share SQL queries in a simple, usable SQL editor, preview the results in the browser, share links to download CSV files, and keep the information flowing!
Explorer values simplicity, intuitive use, unobtrusiveness, stability, and the principle of least surprise.
Django SQL Explorer is inspired by any number of great query and reporting tools out there.
The original idea came from Stack Exchange's Data Explorer, but also owes credit to similar projects like Redash and Blazer.
django-sql-explorer is MIT licensed, and pull requests are welcome.
A view of a query
Viewing all queries
Quick access to DB schema info
Snapshot query results to S3 & download as csv
'explorer.tasks.snapshot_queries': {
'task': 'explorer.tasks.snapshot_queries',
'schedule': crontab(hour=1, minute=0)
}
EXPLORER_TRANSFORMS = [('user', '<a href="https://yoursite.com/profile/{0}/">{0}</a>')]
'explorer.tasks.truncate_querylogs': {
'task': 'explorer.tasks.truncate_querylogs',
'schedule': crontab(hour=1, minute=0),
'kwargs': {'days': 30}
}
curl --header "X-API-TOKEN: <TOKEN>" https://www.your-site.com/explorer/<QUERY_ID>/stream?format=csv
Requires Python 2.7, 3.4, or 3.5. Requires Django 1.7.1 or higher.
Install with pip from github:
pip install django-sql-explorer
Add to your installed_apps:
INSTALLED_APPS = (
...,
'explorer',
...
)
Add the following to your urls.py (all Explorer URLs are restricted via the EXPLORER_PERMISSION_VIEW and EXPLORER_PERMISSION_CHANGE settings. See Settings section below for further documentation.):
url(r'^explorer/', include('explorer.urls')),
Run migrate to create the tables:
python manage.py migrate
You can now browse to https://yoursite/explorer/ and get exploring! It is highly recommended that you also configure Explorer to use a read-only database connection via the EXPLORER_CONNECTION_NAME setting.
An effort has been made to keep the number of dependencies to a minimum.
Python
Name | Version | License |
---|---|---|
sqlparse | 0.1.18 | BS |
unicodecsv | 0.14.1 | BSD |
Python - Optional Dependencies
Name | Version | License |
---|---|---|
celery | 3.1 | BSD |
django-celery | 3.1 | BSD |
Factory Boy | 2.6.0 | MIT |
xlsxwriter | 0.8.5 | BSD |
tinys3 | 0.1.11 | MIT |
JavaScript
Name | Version | License |
---|---|---|
Twitter Boostrap | 3.3.6 | MIT |
jQuery | 2.1.4 | MIT |
jQuery Cookie | 1.4.1 | MIT |
jQuery UI | 1.11.4 | MIT |
Underscore | 1.7.0 | MIT |
Codemirror | 5.15.2 | MIT |
floatThead | 1.4.0 | MIT |
list.js | 1.2.0 | MIT |
pivottable.js | 2.0.2 | MIT |
locally. pivottable.js relies on jQuery UI but for the Sortable method.
Factory Boy is needed if you'd like to run the tests, which can you do easily:
python manage.py test
and with coverage:
coverage run --source='.' manage.py test
then:
coverage report
...99%! Huzzah!
There is also a test_project that you can use to kick the tires. Just creata a new virtualenv, cd into test_project and run start.sh (or walk through the steps yourself) to get a test instance of the app up and running.
Setting | Description | Default |
---|---|---|
EXPLORER_SQL_BLACKLIST | Disallowed words in SQL queries to prevent destructive actions. | ('ALTER', 'RENAME ', 'DROP', 'TRUNCATE', 'INSERT INTO', 'UPDATE', 'REPLACE', 'DELETE', 'ALTER', 'CREATE TABLE', 'SCHEMA', 'GRANT', 'OWNER TO') |
EXPLORER_SQL_WHITELIST | These phrases are allowed, even though part of the phrase appears in the blacklist. | ('CREATED', 'UPDATED', 'DELETED','REGEXP_REPLACE') |
EXPLORER_DEFAULT_ROWS | The number of rows to show by default in the preview pane. | 1000 |
EXPLORER_SCHEMA_INCLUDE_APPS | Show schemas for only these packages in the schema helper. If set to None, show all apps. | None |
EXPLORER_SCHEMA_EXCLUDE_APPS | Don't show schema for these packages in the schema helper, even if listed in EXPLORER_SCHEMA_INCLUDE_APPS. | ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin') |
EXPLORER_CONNECTION_NAME | The name of the Django database connection to use. Ideally set this to a connection with read only permissions | None # Which means use the 'default' connection |
EXPLORER_PERMISSION_VIEW | Callback to check if the user is allowed to view and execute stored queries | lambda u: u.is_staff |
EXPLORER_PERMISSION_CHANGE | Callback to check if the user is allowed to add/change/delete queries | lambda u: u.is_staff |
EXPLORER_TRANSFORMS | List of tuples like [('alias', 'Template for {0}')]. See features section of this doc for more info. | [] |
EXPLORER_RECENT_QUERY_COUNT | The number of recent queries to show at the top of the query listing. | 10 |
EXPLORER_GET_USER_QUERY_VIEWS | A dict granting view permissions on specific queries of the form {userId:[queryId, ...], ...} | {} |
EXPLORER_TOKEN_AUTH_ENABLED | Bool indicating whether token-authenticated requests should be enabled. See "Power Tips", above. | False |
EXPLORER_TOKEN | Access token for query results. | "CHANGEME" |
EXPLORER_TASKS_ENABLED | Turn on if you want to use the snapshot_queries celery task, or email report functionality in tasks.py | False |
EXPLORER_S3_ACCESS_KEY | S3 Access Key for snapshot upload | None |
EXPLORER_S3_SECRET_KEY | S3 Secret Key for snapshot upload | None |
EXPLORER_S3_BUCKET | S3 Bucket for snapshot upload | None |
EXPLORER_FROM_EMAIL | The default 'from' address when using async report email functionality | "django-sql-explorer@example.com" |
EXPLORER_DATA_EXPORTERS | The export buttons to use. Default includes Excel, so xlsxwriter from optional-requirements.txt is needed | [('csv', 'explorer.exporters.CSVExporter'), ('excel', 'explorer.exporters.ExcelExporter'), ('json', 'explorer.exporters.JSONExporter')] |
Release process is documented here. If there are problems with the release, please help me improve the process so it doesn't happen again!