Skip to main content

PostgreSQL-specific data sanitization (null chars, surrogates)

Project description

postgres-data-sanitizers

PostgreSQL-specific data sanitization (null chars, surrogates).

Installation

pip install postgres-data-sanitizers

Usage

from postgres_data_sanitizers import (
    escape_null_chars,
    sanitize_dict_for_postgres,
    validate_postgres_text,
    contains_surrogates
)

# Escape null characters in strings
safe_text = escape_null_chars("hello\x00world")  # "hello\\u0000world"

# Sanitize dictionaries for JSONB storage
data = {"key": "value\x00with\x00nulls"}
safe_data = sanitize_dict_for_postgres(data)

# Validate text fields
text = validate_postgres_text("user input\x00")

# Check for surrogate characters
has_surrogates = contains_surrogates(text)

Features

  • ✅ Escapes null characters (preserves data)
  • ✅ JSONB-safe dictionary sanitization
  • ✅ Surrogate character detection
  • ✅ Zero dependencies
  • ✅ Prevents database crashes

Why This Matters

PostgreSQL rejects null characters (\x00) in TEXT/VARCHAR/JSONB fields, causing:

asyncpg.exceptions.UntranslatableCharacterError

This library escapes rather than removes null characters, preserving data integrity.

License

MIT

Project details


Download files

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

Source Distribution

postgres_data_sanitizers-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

postgres_data_sanitizers-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file postgres_data_sanitizers-0.1.0.tar.gz.

File metadata

  • Download URL: postgres_data_sanitizers-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for postgres_data_sanitizers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 617bb7c66c01668c212d934f244809c7fb8a996b3375d09340d559a5f3c850a2
MD5 7fcfa531a498fc3259b60ae4d80dd821
BLAKE2b-256 fdef085e9a4c8bf93c87aedb16450a82df16c5f0b0aaa7ffde91e35aa7f58693

See more details on using hashes here.

File details

Details for the file postgres_data_sanitizers-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for postgres_data_sanitizers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08bab08bc34f8cf19c15e88567171804fc69307fec1ca1c29e83eadd8755bc4f
MD5 cb2b5d8dbdbabaa77b5821a61bdf924b
BLAKE2b-256 658c10772955acf436590c355f6cd4b9e6dbba790834ee53d7371907e7db7d55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page