A custom function to use ColorBrewer scales in SQLite queries
Project description
sqlite-colorbrewer
A custom function to use ColorBrewer scales in SQLite queries.
Colors are exported from here.
Installation
To install as a Python library and use with the standard SQLite3 module:
pip install sqlite-colorbrewer
To install this plugin in the same environment as Datasette.
datasette install sqlite-colorbrewer
Usage
If you're using this library with Datasette, it will be automatically registered as a plugin and available for use in SQL queries, like so:
SELECT colorbrewer('Blues', 9, 0);
That will return a single value: "rgb(247,251,255)"
To use with a SQLite connection outside of Datasette, use the register
function:
>>> import sqlite3
>>> import sqlite_colorbrewer
>>> conn = sqlite3.connect(':memory')
>>> sqlite_colorbrewer.register(conn)
>>> cursor = conn.execute("SELECT colorbrewer('Blues', 9, 0);")
>>> result = next(cursor)
>>> print(result)
rgb(247,251,255)
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd sqlite-colorbrewer
python3 -mvenv venv
source venv/bin/activate
Or if you are using pipenv
:
pipenv shell
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
To build sqlite_colorbrewer/colorbrewer.py
:
./json_to_python.py
black . # to format the resulting file
ColorBrewer
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
See the ColorBrewer updates for updates to copyright information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlite-colorbrewer-0.2.tar.gz
.
File metadata
- Download URL: sqlite-colorbrewer-0.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80049cd65e94a3fd128284218baa3d71f76df70ffe41d38f3daacf0f857548ea |
|
MD5 | ac3c03831c4b9aff2e65d3a83cbb0585 |
|
BLAKE2b-256 | e134c481ad706f79b5460ad334f72c3a260bd4a4b14b422e6b6ba98e580ad5bc |
File details
Details for the file sqlite_colorbrewer-0.2-py3-none-any.whl
.
File metadata
- Download URL: sqlite_colorbrewer-0.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b81d4288fcf29b03cd8c1c84b4a4425220a59d5cbd32b71818ab2eac945eaf |
|
MD5 | 332b733ae7be71cc8416f3d467422215 |
|
BLAKE2b-256 | 9053c587cc6a96f98b3d433a76896823213551ce212acc7bb4a0418e42448fc0 |