{"id":32929620,"url":"https://github.com/wrannaman/redact-pii-python","last_synced_at":"2026-05-01T23:36:48.108Z","repository":{"id":323507882,"uuid":"1093526429","full_name":"wrannaman/redact-pii-python","owner":"wrannaman","description":"Zero-dependency, blazing-fast regex-based PII redaction with optional compliance dashboard integration. Python package for redactpii.com","archived":false,"fork":false,"pushed_at":"2025-11-10T14:03:17.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-10T16:06:28.654Z","etag":null,"topics":["ai","ai-redaction","anonymization","compliance","data-protection","gdpr","gdpr-compliance","hippaa","langchain","llm","openai","pii","pii-anonymization","pii-detection","pip","python","redaction","security","soc2"],"latest_commit_sha":null,"homepage":"https://redactpii.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wrannaman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-10T13:47:08.000Z","updated_at":"2025-11-10T14:03:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wrannaman/redact-pii-python","commit_stats":null,"previous_names":["wrannaman/redact-pii-python"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/wrannaman/redact-pii-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrannaman%2Fredact-pii-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrannaman%2Fredact-pii-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrannaman%2Fredact-pii-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrannaman%2Fredact-pii-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wrannaman","download_url":"https://codeload.github.com/wrannaman/redact-pii-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrannaman%2Fredact-pii-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283846898,"owners_count":26904663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-11T02:00:06.610Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-redaction","anonymization","compliance","data-protection","gdpr","gdpr-compliance","hippaa","langchain","llm","openai","pii","pii-anonymization","pii-detection","pip","python","redaction","security","soc2"],"created_at":"2025-11-11T12:01:31.733Z","updated_at":"2025-11-11T12:01:53.060Z","avatar_url":"https://github.com/wrannaman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redactpii\n\n[![PyPI Package](https://img.shields.io/pypi/v/redactpii.svg)](https://pypi.org/project/redactpii/)\n\n\u003e **⚡ Zero-dependency, blazing-fast regex-based PII redaction with optional compliance dashboard integration.**\n\n**Python package for [redactpii.com](https://redactpii.com)** - Protect PII before it hits AI APIs with optional SOC 2/HIPAA audit trails.\n\nBuilt for the modern AI stack. Protect PII **before** it hits OpenAI, Anthropic, or LangChain with **optional dashboard integration** for SOC 2 \u0026 HIPAA audit trails.\n\n## ⚡ Zero Dependencies. Blazing Fast. Enterprise Ready.\n\n- **\u003c1ms per operation** - Optimized regex engine\n- **Zero external dependencies** - Pure Python, no bloat\n- **Dashboard integration** - SOC 2/HIPAA audit trails (optional)\n- **Zero-trust security** - Never sends PII, only metadata\n- **Type hints** - Full type safety and IDE support\n\n### Requirements\n\n- **Python 3.8+**\n- **Zero dependencies** (seriously, check your requirements)\n\n## 🚀 Installation \u0026 Usage\n\n```bash\npip install redactpii\n```\n\n### 🔥 Basic Usage\n\n```python\nfrom redactpii import Redactor\n\nredactor = Redactor()\nclean = redactor.redact('Hi David Johnson, call 555-555-5555')\n\n# Result: \"Hi PERSON_NAME, call PHONE_NUMBER\"\n```\n\n### 🛡️ Enterprise Compliance (SOC 2/HIPAA Ready)\n\nEnable **optional dashboard integration** for audit trails:\n\n```python\nfrom redactpii import Redactor\nimport os\n\nredactor = Redactor({\n    'api_key': os.getenv('REDACTPII_API_KEY'),  # Enables compliance dashboard\n    'api_url': 'https://api.redactpii.com/v1/events',  # Your audit endpoint (optional)\n    'rules': {\n        'CREDIT_CARD': True,\n        'EMAIL': True,\n        'NAME': True,\n        'PHONE': True,\n        'SSN': True,\n    },\n})\n\nclean = redactor.redact('CEO john@acme.com called from 555-123-4567 with SSN 123-45-6789')\n\n# Result: \"CEO EMAIL_ADDRESS called from PHONE_NUMBER with SSN US_SOCIAL_SECURITY_NUMBER\"\n\n# 🔒 Zero-trust: Only metadata sent to dashboard\n# 📊 Audit log: {\"sdk_version\": \"1.0.0\", \"pii_type\": \"EMAIL\", \"action\": \"REDACTED\"}\n```\n\n\u003e **🔐 Zero-Trust Guarantee**: Never sends actual PII data. Only anonymized metadata for compliance reporting. Non-blocking requests with 500ms timeout - never impacts your app performance.\n\n### 🎯 PII Detection\n\nBuilt-in patterns for:\n\n- **👤 Names** - Person identification (greeting-based detection)\n- **📧 Emails** - Email addresses\n- **📞 Phones** - US phone numbers (all formats)\n- **💳 Credit Cards** - Visa, Mastercard, Amex, Diners Club\n- **🆔 SSN** - US Social Security Numbers\n\n### 🔍 Check for PII Without Redacting\n\n```python\nfrom redactpii import Redactor\n\nredactor = Redactor({'rules': {'EMAIL': True}})\n\nif redactor.has_pii('Contact test@example.com for details'):\n    print('PII detected!')\n    # Now redact it\n    clean = redactor.redact('Contact test@example.com for details')\n```\n\n### 📦 Redact Objects\n\n```python\nfrom redactpii import Redactor\n\nredactor = Redactor({'rules': {'EMAIL': True}})\n\nuser = {\n    'name': 'John Doe',\n    'email': 'john@example.com',\n    'profile': {\n        'contact': 'contact@example.com',\n    },\n}\n\nclean = redactor.redact_object(user)\n# {\n#   'name': 'John Doe',\n#   'email': 'EMAIL_ADDRESS',\n#   'profile': {\n#     'contact': 'EMAIL_ADDRESS',\n#   },\n# }\n```\n\n### 🤖 Using with LLMs (OpenAI, LangChain)\n\nProtect PII **before** it hits AI APIs. This is your compliance safety net.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExample: Using with OpenAI Client\u003c/b\u003e\u003c/summary\u003e\n\n```python\nfrom redactpii import Redactor\nfrom openai import OpenAI\nimport os\n\nredactor = Redactor({\n    'api_key': os.getenv('REDACTPII_API_KEY'),\n    'rules': {'SSN': True, 'EMAIL': True},\n})\n\nopenai_client = OpenAI()\n\n# 1. Redact the prompt BEFORE you send it\nraw_prompt = 'My SSN is 123-45-6789 and my email is test@example.com'\nsafe_prompt = redactor.redact(raw_prompt)\n\n# 2. Send the \"safe\" prompt to the LLM\ncompletion = openai_client.chat.completions.create(\n    messages=[{'role': 'user', 'content': safe_prompt}],\n    model='gpt-4o',\n)\n\n# 3. Your audit log on redactpii.com now has proof\n#    of the redaction *before* it hit OpenAI.\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eExample: Using with LangChain\u003c/b\u003e\u003c/summary\u003e\n\n```python\nfrom redactpii import Redactor\nfrom langchain_openai import ChatOpenAI\nimport os\n\n# 1. Init the redactor with your dashboard API key\nredactor = Redactor({'api_key': os.getenv('REDACTPII_API_KEY')})\nmodel = ChatOpenAI()\n\n# 2. Create a middleware function to redact input\ndef redacting_middleware(input_data):\n    if redactor.has_pii(input_data['query']):\n        # Redact the input and log it to your dashboard\n        safe_query = redactor.redact(input_data['query'])\n        return {**input_data, 'query': safe_query}\n    return input_data\n\n# 3. Use the middleware before sending to LLM\nuser_input = {'query': 'My email is john@acme.com'}\nsafe_input = redacting_middleware(user_input)\nresult = model.invoke(safe_input['query'])\n\n# Your prompt was safely redacted before hitting the LLM.\n```\n\n\u003c/details\u003e\n\n### 🎨 Customization\n\n#### Configure Rules\n\n```python\nredactor = Redactor({\n    'rules': {\n        'CREDIT_CARD': True,  # Enable credit card detection\n        'EMAIL': True,  # Enable email detection\n        'NAME': False,  # Disable name detection\n        'PHONE': True,  # Enable phone detection\n        'SSN': False,  # Disable SSN detection\n    },\n})\n```\n\n#### Custom Regex Patterns\n\n```python\nimport re\nfrom redactpii import Redactor\n\nredactor = Redactor({\n    'rules': {'EMAIL': True},\n    'custom_rules': [\n        re.compile(r'\\b\\d{5}\\b'),  # 5-digit codes\n        re.compile(r'\\bSECRET-\\d+\\b'),  # Secret codes\n    ],\n})\n```\n\n#### Global Replacement\n\n```python\nredactor = Redactor({\n    'rules': {'EMAIL': True},\n    'global_replace_with': '[REDACTED]',  # All PII types use this replacement\n})\n\nredactor.redact('test@example.com')  # \"[REDACTED]\"\n```\n\n### 🛡️ Dashboard Hook Configuration\n\n```python\nredactor = Redactor({\n    'api_key': 'your-api-key',\n    'api_url': 'https://api.redactpii.com/v1/events',  # Optional, defaults to this\n    'fail_silent': True,  # Default: True (fail silently if dashboard is down)\n    'hook_timeout': 500,  # Default: 500ms timeout for dashboard requests\n    'rules': {'EMAIL': True},\n})\n```\n\n**Dashboard Payload:**\n\n```json\n{\n  \"sdk_version\": \"1.0.0\",\n  \"sdk_language\": \"python\",\n  \"events\": [\n    { \"pii_type\": \"EMAIL\", \"action\": \"REDACTED\" },\n    { \"pii_type\": \"PHONE_NUMBER\", \"action\": \"REDACTED\" }\n  ]\n}\n```\n\n## 🧪 Quality Assurance\n\n- **Comprehensive tests** covering all APIs and edge cases\n- **100% type hints** with mypy strict mode\n- **Zero unsafe operations** - full type safety\n- **Pre-commit hooks** - automatic linting and type checking\n\n### 🏃‍♂️ Development\n\n```bash\n# Install dependencies\npip install -e \".[dev]\"\n\n# Run tests\npytest\n\n# Run with coverage\npytest --cov=redactpii --cov-report=html\n\n# Type checking\nmypy redactpii\n\n# Linting\nruff check redactpii tests\n```\n\n### 🤝 Contributing\n\nWe welcome contributions! This library powers compliance for thousands of applications.\n\n---\n\n**Built for the modern AI stack with optional SOC 2/HIPAA audit logs.**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrannaman%2Fredact-pii-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwrannaman%2Fredact-pii-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrannaman%2Fredact-pii-python/lists"}