SafeContext

For developers

Build a connector.

A connector copies data from one place, like a chat app, an export file or a folder of transcripts, into SafeContext. Every item is scrubbed on the Mac before it's stored.

  • Built inGmailGoogle CalendariMessage
  • Coming soonWhatsAppCall recordings

Anyone can write one. They ship inside the app.

There's no plugin folder, and SafeContext never loads code from outside the app. A connector sees raw data before the scrubber does, so every one is reviewed before it reaches anyone's Mac. That's what keeps the promise that your data is scrubbed on your Mac.

  1. Open a pull request

    Add your reader and connector, register it, and pass the conformance kit.

  2. It's reviewed

    We check it against the seven rules below. A pull request that breaks one isn't merged.

  3. It ships in the next release

    Merged connectors go out in the next signed, notarized build of SafeContext.

The rules

These protect what SafeContext promises its users. A pull request that breaks one isn't merged.

  1. Read-onlyNever send, change or delete anything at the source.
  2. Nothing leaves the MacNo network calls, except to a service's own official API for a sign-in connector. No analytics and no phoning home.
  3. Everything goes through the scrubberReturn RawItems from to_item and let ReaderSource do the rest. Never write to the store or override sync(); the registry refuses a connector that does.
  4. No raw data in logsLog ids and counts only. Never message text, names, numbers or addresses.
  5. Ask, don't takeDeclare every permission in requirements with a plain reason. Check access without triggering a macOS prompt, and raise NeedsPermission with help that tells the user what to do.
  6. Fixture data only in testsBuild fake databases or files in a temp folder. Never read real user data, not even your own.
  7. No new dependenciesNot without asking first in the pull request.

How to build one

Connectors are Python. Start from tests/example_connector.py, a complete working connector for a chat export file.

1. The reader

In src/safecontext/readers/. It knows the source's format and nothing about SafeContext: a function or class that yields plain records, oldest first, starting after a cursor.

2. The connector

In src/safecontext/sources/. Subclass ReaderSource. Batching, scrubbing, storing, resuming from the cursor, progress and error handling all come for free.

  • idLowercase and stable. Items are stored under it, so it never changes.
  • name, descriptionShown on the Sources screen.
  • kindsOne or more of message, event, chat, transcript. The scrubber picks its rules by kind, so new kinds aren't allowed.
  • api_version1, the current connector API.
  • requirementsWhat the connector needs, each with a reason for the user.
  • read(cursor)Records after cursor (None means everything), oldest first.
  • to_item(record)One record to one RawItem, or None to skip it.
  • cursor_of(record)A string that makes read resume after this record.
  • check_access()Optional. Raise NeedsPermission when access is missing.
Trimmed from tests/example_connector.py
class ChatExportSource(ReaderSource):
    id = "chat_export"
    name = "Chat export"
    description = "Chats from an exported JSON Lines file you choose."
    kinds = ("chat",)
    api_version = 1
    requirements = (Requirement(FILE, "", "A file you choose",
        "SafeContext reads only the export file you pick, read-only."),)

    def read(self, cursor):
        return read_export(self.path, int(cursor or 0))

    def cursor_of(self, record):
        return str(record.line_no)

    def to_item(self, r):
        if not r.text.strip():
            return None  # nothing to keep
        return RawItem(id=r.id, kind="chat", thread_id=r.chat,
                       date_ms=r.ts_ms, sender=r.sender,
                       participants=[r.sender], title=r.chat,
                       text=r.text)

3. Register it

Add your class to CONNECTORS in sources/__init__.py. One line.

4. Pass the conformance kit

Add a ConnectorFixture to tests/test_connector_conformance.py, add your own tests for to_item, and run .venv/bin/pytest. Every test must pass.

The kit's nine checks

  • The declaration is valid and registered
  • A first sync adds up, with only declared kinds
  • A second sync resumes without duplicates
  • A bad record is dropped and the sync goes on
  • A crash while reading is reported and retried
  • An undeclared kind is never stored
  • Missing access raises a permission the app can explain
  • Disconnecting deletes the connector's data and cursor
  • Card numbers and one-time codes never reach the store's files

Connectors that need a sign-in, like Gmail and Google Calendar, sync through their service's API and aren't covered by the kit yet. Open an issue before you start one, so sign-in and token storage can be designed with you.

Ready to start?

The guide has the full details and the pull request checklist.