Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/dxray.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# dxray, the Python data library in python/dxray: tests on every change, and publishing to PyPI by hand.
#
# Publishing uses PyPI Trusted Publishing, so no password or token is stored anywhere. One-time setup on
# https://pypi.org/manage/account/publishing/ ("Add a new pending publisher"):
# PyPI project name: dxray Owner: fcopensource Repository: veyraeditor
# Workflow name: dxray.yml Environment name: pypi
# Then: Actions -> "dxray (Python)" -> Run workflow -> publish: pypi.
# (For a trial run first, add the same pending publisher on https://test.pypi.org with environment "testpypi".)
name: dxray (Python)

on:
push:
branches: [main]
paths: ["python/dxray/**", ".github/workflows/dxray.yml"]
pull_request:
paths: ["python/dxray/**", ".github/workflows/dxray.yml"]
workflow_dispatch:
inputs:
publish:
description: Publish this version
type: choice
options: [none, testpypi, pypi]
default: none

permissions:
contents: read

defaults:
run:
working-directory: python/dxray

jobs:
test:
name: Python ${{ matrix.python }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
python: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
- run: python -m pip install --upgrade pip
- run: python -m pip install ".[all]" pytest
- run: python -m pytest -q -p no:cacheprovider

build:
name: Build
needs: test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install build twine
- run: python -m build
- run: python -m twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: dist
path: python/dxray/dist/

publish:
name: Publish to ${{ inputs.publish }}
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.publish != 'none'
runs-on: ubuntu-22.04
environment:
name: ${{ inputs.publish }}
url: ${{ inputs.publish == 'pypi' && 'https://pypi.org/project/dxray/' || 'https://test.pypi.org/project/dxray/' }}
permissions:
id-token: write # Trusted Publishing
defaults:
run:
working-directory: .
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ inputs.publish == 'testpypi' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
packages-dir: dist/
112 changes: 112 additions & 0 deletions docs/PUBLISHING-PYTHON-LIBRARIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Publishing our Python libraries to PyPI

How `dxray` and `veyra-snap` (in `python/`) get to `pip install`. Read it once top to bottom; after that, a release is
the five steps in [Every release](#every-release).

## How it fits together

- **PyPI** (pypi.org) is where `pip install` downloads packages from. Anyone can publish; a name belongs to whoever
publishes it first.
- **A release** is a version number (like `1.0.0`) plus two files built from the code: a **wheel** (`.whl`, ready to
install) and an **sdist** (`.tar.gz`, the source). `pyproject.toml` describes the package: name, description,
dependencies, the README that becomes the PyPI page.
- **A version can be uploaded only once, ever.** If `1.0.0` has a mistake, you publish `1.0.1`. You can't replace or
re-upload a version, even after deleting it.
- **Trusted Publishing** lets GitHub Actions upload to PyPI without a password or token stored anywhere: PyPI trusts a
specific workflow in a specific repository. That's how ours are set up.

Each library has its own workflow that tests it on every pull request and publishes when you ask:

| Library | Folder | Workflow | PyPI page |
|---|---|---|---|
| dxray | `python/dxray` | `.github/workflows/dxray.yml` | https://pypi.org/project/dxray/ |
| veyra-snap | `python/veyra-snap` | `.github/workflows/veyra-snap.yml` | https://pypi.org/project/veyra-snap/ |

## One-time setup (about 10 minutes)

### 1. A PyPI account

1. Sign up at https://pypi.org/account/register/ and confirm the email.
2. Turn on **two-factor authentication** (Account settings → Add 2FA). PyPI requires it to publish.
3. Optional, for trial runs: do the same at https://test.pypi.org (a separate practice site with separate accounts).

### 2. Tell PyPI to trust our workflow (a "pending publisher")

The project doesn't exist on PyPI yet, so you reserve it for our workflow:

1. Go to https://pypi.org/manage/account/publishing/ → **Add a new pending publisher** → **GitHub**.
2. Fill it in **exactly** (one entry per library):

| Field | dxray | veyra-snap |
|---|---|---|
| PyPI Project Name | `dxray` | `veyra-snap` |
| Owner | `fcopensource` | `fcopensource` |
| Repository name | `veyraeditor` | `veyraeditor` |
| Workflow name | `dxray.yml` | `veyra-snap.yml` |
| Environment name | `pypi` | `pypi` |

3. Click **Add**. The first successful publish turns it into a normal project you own.

For trial runs on TestPyPI, add the same entries at https://test.pypi.org/manage/account/publishing/ with environment
name `testpypi`.

### 3. Optional: a safety catch in GitHub

In the repository: **Settings → Environments → New environment** named `pypi`, then tick **Required reviewers** and
add yourself. A publish then waits until you click **Approve**, so nobody publishes by accident.

## Every release

1. **Merge the code.** The library's pull request must be merged into `main`, with its tests green.
2. **Optional practice run:** Actions → **dxray (Python)** (or **veyra-snap (Python)**) → **Run workflow** →
branch `main`, publish: **testpypi**. Then try it:

```console
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ dxray
```

3. **Publish:** Actions → the same workflow → **Run workflow** → publish: **pypi**.
The run tests the library, builds the wheel and sdist, checks them with `twine check`, and uploads.
4. **Check it:** open https://pypi.org/project/dxray/ and, in a fresh terminal:

```console
pip install dxray
dxray --version
```

5. **Tell people:** the website pages switch to `pip install …` by themselves within the hour.

## Releasing a new version

1. On a new branch, change the code and add tests.
2. Bump the version in the library's `src/<package>/__init__.py` (`__version__ = "1.0.1"`). Use
[semantic versioning](https://semver.org): `1.0.1` for fixes, `1.1.0` for new features, `2.0.0` when existing code
using the library would break.
3. Add a section at the top of its `CHANGELOG.md`.
4. Pull request → merge → [Every release](#every-release) from step 2.

## When something goes wrong

| What you see | What it means | What to do |
|---|---|---|
| `invalid-publisher` in the upload step | The pending publisher doesn't match the run | Compare every field in step 2 above with the workflow file name and environment, letter by letter |
| `File already exists` | That version is already on PyPI | Bump the version; versions can't be re-uploaded |
| `The name 'x' is too similar to an existing project` | PyPI blocks look-alike names (`data-xray` blocks `dataxray`) | Choose another name in `pyproject.toml` |
| The run waits forever | The `pypi` environment needs your approval | Open the run and click **Review deployments → Approve** |
| `twine check` fails | The README can't be shown on PyPI | Fix the Markdown it names |
| A broken release is out | Users installing it get the bug | Publish a fixed version; on PyPI you can also **yank** the bad one (Manage → Releases), which hides it from new installs without breaking anyone pinned to it |

## Doing it by hand (to understand it, or without GitHub)

The workflow does exactly this:

```console
cd python/dxray
python -m pip install build twine
python -m build # makes dist/dxray-1.0.0-py3-none-any.whl and dist/dxray-1.0.0.tar.gz
python -m twine check dist/* # will PyPI accept it and show the README?
python -m twine upload dist/* # asks for an API token from https://pypi.org/manage/account/token/
```

Use a token (username `__token__`, the token as the password), never your PyPI password, and prefer the workflow so
no token has to live on anyone's machine.
6 changes: 6 additions & 0 deletions python/dxray/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__/
*.egg-info/
dist/
build/
.pytest_cache/
examples/*.html
16 changes: 16 additions & 0 deletions python/dxray/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

## 1.0.0

First release.

- `dx.scan(data, target=None)`: what each column really is, data problems with the pandas line that fixes each one,
ranked insights in plain English (relationships, group differences, what drives a target, trends and biggest
changes, 80/20 concentration, lopsided averages), and a 0-100 health score.
- Reports in the terminal, as a rich Jupyter view, as one self-contained HTML page with inline SVG charts, as
Markdown and as JSON.
- `dx.clean(data)`: the safe, mechanical fixes, with a log of every change. Never drops outliers or fills gaps.
- `dx.for_llm(data)`: the dataset described for an AI model in compact Markdown.
- `dx.ask(data, question)`: answers from Claude (`pip install "dxray[ai]"`), with the description cached across
questions.
- The `dxray` command for CSV, TSV, Excel, Parquet and JSON files.
21 changes: 21 additions & 0 deletions python/dxray/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 FlightCoders

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
129 changes: 129 additions & 0 deletions python/dxray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# dxray: an X-ray for your data

**One line tells you what's wrong with a dataset and what stands out in it, in plain English.** Then clean it, share
a report, or ask Claude about it.

```python
import dxray as dx

dx.scan(df, target="revenue")
```

```text
◆ dxray orders.csv 4,040 rows × 13 columns. Health 53/100: 12 issues, 16 insights.

What stands out
→ What drives 'revenue': 'ad_spend', 'price', 'tier'.
→ 'price' differs a lot by 'tier': 'Premium' averages 221, 5.2× 'Basic' (42.4).
→ Total 'revenue' rose 122% from 2026-01 to 2026-12 (by month).
→ Total 'revenue' dropped 61% in 2026-03 (vs 2026-02), the biggest fall of any month.
→ The top 20% of 'customer' values (68 of 338) account for 83% of total 'revenue'.

Data problems
● 'price' holds numbers stored as text (like '$46.25', '$95.54'), so you can't sum or average it.
fix: df['price'] = pd.to_numeric(df['price'].astype(str).str.replace(r'[,$€£₹¥%\s]', '', regex=True), errors='coerce')
● 'region' spells the same value different ways (like 'NORTH', 'North', 'north').
fix: df['region'] = df['region'].str.strip().str.title()
● 40 rows (1.0%) are exact duplicates of another row.
fix: df = df.drop_duplicates()
```

```console
pip install dxray
```

Works with pandas DataFrames (and polars or pyarrow tables, dicts, lists) and with CSV, Excel, Parquet and JSON files.
Python 3.9+. Only needs pandas and numpy.

## Why dxray

Every analysis starts the same way: twenty minutes of `df.info()`, `df.describe()`, `value_counts()` and squinting,
before you know whether the data can be trusted or where the story is. dxray does that pass for you, in one line, and
writes it in sentences:

- **What each column really is.** Not just `object` and `int64`: money stored as text, dates stored as text, yes/no
columns, IDs, emails, categories, free text, constants.
- **What's wrong, and the exact fix.** Missing values (including "N/A", "-", "null" hiding as text), duplicates,
repeated IDs, the same category spelled three ways, stray spaces, numbers stored as text, impossible outliers,
sentinel values like -999. Every problem comes with the pandas line that fixes it.
- **What stands out.** The strongest relationships, the groups that differ, what drives the column you care about,
trends over time and the biggest jumps and drops, 80/20 concentration, and averages that lie. Ranked, so the best
come first.
- **A health score** from 0 to 100, so you can see at a glance whether the data is ready.

## A report you can share

```python
report = dx.scan(df, target="revenue")
report # in Jupyter: a rich report with charts
report.to_html("report.html") # one self-contained page: email it, attach it, open it anywhere
report.to_markdown() # for a PR, a wiki, a notebook cell
report.to_json() # for code
```

<img src="https://raw.githubusercontent.com/fcopensource/veyraeditor/main/python/dxray/media/report.png" alt="The dxray HTML report for orders.csv: a health score of 53, and insight cards with charts: what drives revenue, price by tier, revenue rising through the year, the March drop, and the top customers bringing 83% of revenue" width="100%">

## Clean it, safely

```python
clean_df, log = dx.clean(df)
print(log)
```

```text
dxray cleaned 4,040 rows → 4,000 rows, 7 changes
✓ 'order_date': dates stored as text are now dates
✓ 'region': merged different spellings of the same value (111 values)
✓ 'price': 31 values like 'N/A' or '-' are now missing values
✓ 'price': numbers stored as text are now numbers
✓ Dropped 40 duplicate rows
```

`dx.clean()` only makes mechanical fixes and tells you every one. It never drops outliers or fills in missing values:
those are decisions about your data, so the report tells you about them and you decide. Your original DataFrame is
left untouched.

## Made for AI

**Give any AI model your dataset, without pasting a million rows.** `dx.for_llm(df)` describes the data in compact
Markdown: every column with its type and statistics (computed from all rows), a few sample rows, the problems and the
findings. A few thousand tokens instead of your whole table.

```python
prompt = dx.for_llm(df, target="revenue")
```

**Or just ask.** With `pip install "dxray[ai]"` and an
[Anthropic API key](https://console.anthropic.com), `dx.ask()` sends that description to Claude:

```python
dx.ask(df, "Why did revenue drop in March, and is the data trustworthy enough to report?")
```

Claude sees dxray's description, not your rows. Asking several questions about the same data reuses the cached
description, so follow-ups are faster and cheaper. Choose `effort="low"`, `"medium"` (default) or `"high"`, a
`model=`, or pass your own `client=anthropic.Anthropic(...)`.

## From the command line

```console
$ dxray sales.csv --target revenue --html report.html
$ dxray sales.csv --clean sales_clean.csv
$ dxray sales.csv --llm > context.md
$ dxray sales.csv --ask "Which region is growing fastest?"
$ dxray sales.csv --json
```

## Good to know

- **Big data:** columns are profiled on every row; the relationship and trend analysis uses a 200,000-row random
sample, so a million-row table still takes seconds.
- **Correlation isn't cause.** dxray tells you what moves together and what differs; deciding why is still your job.
- **Trends** use the table's main date column (it skips birth, signup and join dates), leave out thin periods, and
can't be faked by a few typos like a quantity of 9,999.
- **Private by default.** Everything runs locally. Only `dx.ask()` sends anything anywhere: the description, to the
Anthropic API.

## License

MIT. Made by [FlightCoders](https://flightcoders.com), the team behind the [Veyra](https://veyraeditor.com) editor.
Loading
Loading