Skip to main content

NotPixel Python SDK (notpixel)

Official Python SDK for NotPixel — privacy-first contextual monetization for LLM applications, agents, and backends (FastAPI, Django, Flask, LangChain, LlamaIndex, CrewAI).

Installation

pip install notpixel

Quick Start (Async — FastAPI / LangChain)

from notpixel import AsyncAds

# Privacy=True by default: generates 384-d embeddings locally (BAAI/bge-small-en-v1.5)
# User prompts NEVER leave your server.
ads = AsyncAds(publisher_id="pub_10565")

# 1. Fetch a contextual ad + run your LLM in parallel (best-effort)
result = await ads.respond(
    input="How do I optimize PostgreSQL queries with indexes?",
    llm=lambda: call_my_llm("How do I optimize PostgreSQL queries with indexes?"),
)
print(result.text)  # LLM response + sponsored ad block (if matched)

# 2. Track events
if result.ad:
    await ads.impression(result.ad)
    await ads.track_click(result.ad, metadata={"source": "fastapi_chat"})
    await ads.track_conversion(
        result.ad,
        type="signup",
        value_cents=2900,
        external_id="order_12345",
    )

Synchronous Usage (Django WSGI / Scripts)

from notpixel import Ads

ads = Ads(publisher_id="pub_10565")
ad = ads.get_ad(input="Best serverless Postgres database")
if ad:
    print(ad.text)
    ads.track_click(ad)

Privacy Modes

  • privacy=True (Default): Generates 384-dimensional embeddings locally using FastEmbed with the same quantized Xenova/bge-small-en-v1.5 artifact as the TypeScript SDK, attention-mask mean pooling and L2 normalization. The built-in FastEmbed BGE entry uses CLS pooling and must not be substituted for this configuration. If local embedding fails, get_ad() emits on_error and returns None — never falling back to transmitting raw or sanitized text.
  • privacy=False: Sanitizes PII (emails, phone numbers), truncates to 256 characters, and sends mode="standard" to https://api.notpixel.ai/api/v1/pick.

Releases (maintainers)

Python releases use their own version and tags (python-v0.1.0), independently of npm. Keep pyproject.toml and src/notpixel/__init__.py versions aligned.

.github/workflows/publish-python.yml builds a wheel and source distribution, checks their metadata and contents, and installs the wheel with runtime dependencies to run the tests on Python 3.10–3.13. Tests use simulated transports and embeddings; they do not call production ad endpoints or download model weights.

One-time setup: create the GitHub environment pypi and register a pending Trusted Publisher in PyPI account publishing:

Field Value
PyPI project notpixel
GitHub owner Cocco-Enterprises
Repository notpixel
Workflow filename publish-python.yml
Environment pypi

To release an already committed version:

git tag -a python-v0.1.0 -m "notpixel Python 0.1.0"
git push origin python-v0.1.0

Only matching python-v* tags publish. Pull requests, pushes to main, and manual runs with dry_run=true build and test without uploading. Publishing uses PyPI Trusted Publishing (OIDC), with no permanent API token. After publication, confirm the version on PyPI and test pip install notpixel==0.1.0 in a fresh environment.

Metadata

Release files for notpixel 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notpixel 0.1.0
File Size Uploaded Provenance
notpixel-0.1.0.tar.gz 16.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for notpixel 0.1.0
File Interpreter ABI Platform
notpixel-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.7 kB

Release files / notpixel-0.1.0.tar.gz

Download URL notpixel-0.1.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5c273bfa5e7e26fbb9d9e911a698712e87dd5e262176ed5c225543067a5ba770
BLAKE2b-256 checksum
How to use checksums
283881ee19a429d36ea9f65a34155e2d89983bb22a6d6fa961580a49f443cf6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / notpixel-0.1.0-py3-none-any.whl

Download URL notpixel-0.1.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e190e2a1a59873d1d976e470433ca653f4fb5b6d76ae1d900a71a25a79095c2a
BLAKE2b-256 checksum
How to use checksums
27fc789a595aa99889a3488fd89f9e57ee47cd8e7efcbd821175ed1c3e5d71f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for notpixel 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for notpixel-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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