query_scalar
- query_scalar(sql: str, version: str | int | float | VersionInfo | None = None, *, prefix: Sequence[str] | None = None, **kwargs: Any) Any[source]
Ensure the data is available, run the query, then extract the result.
Similar to
query(), but automatically unpacks the value, assuming that only one record is returned with just a single column.- Parameters:
sql – A SQL query string or table name
version – The version number of ChEMBL to get. If none specified, uses
latest()to look up the latest.prefix – The directory inside
pystowto usekwargs – keyword arguments to pass through to
pandas.read_sql(), such asindex_col.
- Returns:
A value (int, str, etc.) from the database.
Example: .. code-block:: python
import chembl_downloader
sql = “SELECT COUNT(activity_id) FROM activities” count: int = chembl_downloader.query_one(sql)