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.1.tar.gz (15.0 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.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nsds-0.4.1.tar.gz
  • Upload date:
  • Size: 15.0 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.1.tar.gz
Algorithm Hash digest
SHA256 a1dae4611cfff39d54246d76c135646c7038b9b1735ecbc49197e1392429934a
MD5 04c97d8498deef92581b08413e43cc3f
BLAKE2b-256 2ea1b5f7e8c4c68fcb3b482aeb29d7b4bacbd9dba3d9862f8959638cc087d639

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nsds-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f55de26e9c6451c868dfd8197fb58e41e7e439cd70afc3d5616a55c954d736cf
MD5 6fddccc75b301eefc9ffce482714b405
BLAKE2b-256 8ae43c2b021252e7189cff86dd7faa18e4696869d033f105d52b85cf8e7329f8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.4.0

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