Skip to main content

nsds

Personal toolkit for DataScience tasks, runs locally and on Databricks.

Install

pip install nsds                # core: pandas helpers, metrics, utils
pip install 'nsds[notebook]'    # plotly, itables, tqdm, IPython, dotenv
pip install 'nsds[sql]'         # databricks-sql-connector
pip install 'nsds[gsheets]'     # gspread
pip install 'nsds[all]'

Everything outside the core is imported lazily, so a bare install stays small and nsds never pulls in a pyspark that would shadow the one on a cluster.

Quickstart

import nsds

nsds.setup()

setup() is the only thing in the package with side effects: importing any module does nothing on its own. It installs the pandas extensions, sets display options, selects the compact plotly renderer and loads a .env. The last two only apply locally and are skipped on a Databricks cluster.

nsds.setup(itables=True, logging=True)   # opt in
nsds.setup(plotly=False, dotenv=False)   # opt out

What is in it

Module Contents
nsds.frame install(), read_csvs, read_csv_pyarrow, merge_insert_at, dt_group, percentiles
nsds.charts prediction_scatter_plot, dual_y_figure, calculate_axis_range, Colors
nsds.tables show() — itables with sensible defaults
nsds.io.sql read_sql(), as_spark=True
nsds.io.gsheets get_gspread_client(), overwrite_worksheet, spark_df_to_rows
nsds.metrics r2_score, r2_adjusted, smape
nsds.utils datetime_utils, round_half_up, gini_inequality_coefficient, parameter_names, show_mac_notification
nsds.runtime RUNTIME_ENV, IS_DATABRICKS

DataFrame extensions

nsds.setup() attaches these to both pd.DataFrame and pd.Series, without ever shadowing an existing pandas attribute:

df.vc(show_cumulative=True)        # value_counts with percentages
df.missing()                       # NaN / zero / empty-string report
df.sortd("amount")                 # sort_values, descending
df.preview()                       # display a few rows
df.show(nrows=50)                  # display without truncating columns
df.explode_all()
df.memory_mb()
df.to_csv_("out.csv", add_date_to_filename="day")
df.apply_row_wise(func)            # columns inferred from the signature

Static analysers cannot see monkey-patched attributes, so an editor will not autocomplete these on a DataFrame — Jupyter's runtime completion will. Everything else in the package is normally typed and ships py.typed.

Reading SQL

Same call in both environments. On a cluster it uses the active SparkSession; locally it opens a databricks-sql-connector connection from DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH and DATABRICKS_TOKEN, or from arguments you pass directly.

from nsds.io.sql import read_sql

df = read_sql("SELECT * FROM t WHERE day = :day", {"day": "2026-01-01"})
sdf = read_sql("SELECT * FROM t", as_spark=True)   # Databricks only

On Databricks

%pip install 'nsds[gsheets]'

get_gspread_client() can take its service-account JSON from a Databricks secret:

from nsds.io.gsheets import get_gspread_client

client = get_gspread_client(secret_scope="my-scope", secret_key="gcp-service-account")

or from the GSPREAD_SECRET_SCOPE and GSPREAD_SECRET_KEY environment variables.

Development

uv sync --all-extras
uv run pytest
uv run ruff check src tests --fix

Releasing

Versions live in pyproject.toml and are read back at runtime via package metadata. Publish is local for now (UV_PUBLISH_TOKEN / UV_PUBLISH_TOKEN_TEST in a gitignored .envrc). Later: restore a tag-triggered workflow and set UV_PUBLISH_TOKEN as a repo Action secret once 2FA is available on the personal GitHub account.

uv version --bump patch
git commit -am "Release $(uv version --short)" && git tag "v$(uv version --short)"
git push --follow-tags

rm -rf dist && uv build
uv publish --publish-url https://test.pypi.org/legacy/ --token "$UV_PUBLISH_TOKEN_TEST"  # optional smoke
uv publish --token "$UV_PUBLISH_TOKEN"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsds-0.4.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nsds-0.4.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file nsds-0.4.0.tar.gz.

File metadata

  • Download URL: nsds-0.4.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nsds-0.4.0.tar.gz
Algorithm Hash digest
SHA256 fe241fe5f80b335e98c9de3255c8b85e4ef13bdd2d5ad14b33d23a5b3cfc037e
MD5 963cb8a426e7fb107dae34c3c84a44c2
BLAKE2b-256 48822f736e0dca8f0e65f22852864d9955436d70359711d7f85f577f09e369d5

See more details on using hashes here.

File details

Details for the file nsds-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: nsds-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nsds-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c15d24dc63a525c9235908b9d968a902e0250dbb84f8a5c6f05d238c1de1c387
MD5 25051ce06e6c8920152fb36afaa4d05e
BLAKE2b-256 461cc47318b98368fd2cc3dde170e7ccc4e218da0e95e7e612d326955cf376ce

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page