API¶
Warning
The Python API for Mimeogram is currently unofficial and should be considered unstable. The package is primarily intended for use as a command-line tool. Any direct use of the Python modules may break without warning in future versions.
Package mimeogram¶
A toolkit for exchanging collections of files with Large Language Models (LLMs). Mimeogram bundles multiple files into a single clipboard-ready document while preserving directory structure and metadata, making it ideal for code reviews, project sharing, and LLM interactions.
Module mimeogram.acquirers¶
Content acquisition from various sources.
Module mimeogram.apply¶
Application of mimeograms.
- class mimeogram.apply.Command(*, source: Annotated[str, Doc(" Source file for mimeogram.\n\n Defaults to stdin if '--clip' not specified.\n ")] = '-', clip: Annotated[bool | None, Doc(' Read mimeogram from clipboard instead of file or stdin. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--clipboard', '--from-clipboard', prefix_name=None, constructor_factory=None)] | None = None, mode: Annotated[ReviewModes | None, Doc(" Controls how changes are reviewed.\n\n 'silent': Apply without review.\n 'partitive': Review each change interactively.\n\n Partitive, if not specified and on a terminal.\n Silent, if not specified and not on a terminal.\n "), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--review-mode', prefix_name=None, constructor_factory=None)] | None = None, base: Annotated[Path | None, Doc(' Base directory for relative locations.\n\n Defaults to current working directory.\n '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--base-directory', prefix_name=None, constructor_factory=None)] | None = None, force: Annotated[bool | None, Doc('Override protected path checks.')] | None = None)¶
Bases:
CliCommandApplies mimeogram to filesystem locations.
- base: Annotated[Path | None, Doc(' Base directory for relative locations.\n\n Defaults to current working directory.\n '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--base-directory', prefix_name=None, constructor_factory=None)]¶
- clip: Annotated[bool | None, Doc(' Read mimeogram from clipboard instead of file or stdin. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--clipboard', '--from-clipboard', prefix_name=None, constructor_factory=None)]¶
- mode: Annotated[ReviewModes | None, Doc(" Controls how changes are reviewed.\n\n 'silent': Apply without review.\n 'partitive': Review each change interactively.\n\n Partitive, if not specified and on a terminal.\n Silent, if not specified and not on a terminal.\n "), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--review-mode', prefix_name=None, constructor_factory=None)]¶
- class mimeogram.apply.ContentAcquirer(*args, **kwargs)¶
Bases:
ProtocolAcquires content for apply command.
- class mimeogram.apply.StandardContentAcquirer¶
Bases:
ContentAcquirerStandard implementation of content acquisition.
- async mimeogram.apply.apply(auxdata: Globals, command: Command, *, acquirer: ContentAcquirer | AbsentSingleton = absence.absent, parser: Callable[[str], Sequence[Part]] | AbsentSingleton = absence.absent, updater: Callable[[Globals, Sequence[Part], ReviewModes], Coroutine[None, None, None]] | AbsentSingleton = absence.absent) Never¶
Applies mimeogram.
Module mimeogram.cli¶
Command-line interface.
- class mimeogram.cli.Cli(*, application: ~mimeogram.__.application.Information, configfile: str | None = None, inscription: ~mimeogram.__.inscription.Control = Control(mode=<Modes.Rich: 'rich'>, level=None), command: ~mimeogram.create.Annotated[~mimeogram.create.Command, ~tyro.conf._confstruct._SubcommandConfig(name=create, default=<NonpropagatingMissingType id='140688848858624'>, description=None, prefix_name=False, constructor_factory=None)] | ~mimeogram.apply.Annotated[~mimeogram.apply.Command, ~tyro.conf._confstruct._SubcommandConfig(name=apply, default=<NonpropagatingMissingType id='140688848858624'>, description=None, prefix_name=False, constructor_factory=None)] | ~mimeogram.prompt.Annotated[~mimeogram.prompt.Command, ~tyro.conf._confstruct._SubcommandConfig(name=provide-prompt, default=<NonpropagatingMissingType id='140688848858624'>, description=None, prefix_name=False, constructor_factory=None)] | ~mimeogram.cli.Annotated[~mimeogram.cli.VersionCommand, ~tyro.conf._confstruct._SubcommandConfig(name=version, default=<NonpropagatingMissingType id='140688848858624'>, description=None, prefix_name=False, constructor_factory=None)])¶
Bases:
objectMimeogram: hierarchical data exchange between humans and LLMs.
- application: Information¶
- command: _SubcommandConfig(name=version, default=<NonpropagatingMissingType id='140688848858624'>, description=None, prefix_name=False, constructor_factory=None)]¶
- class mimeogram.cli.VersionCommand¶
Bases:
CliCommandPrints version information.
- mimeogram.cli.execute()¶
Entrypoint for CLI execution.
Module mimeogram.create¶
Creation of mimeograms.
- class mimeogram.create.Command(*, sources: Annotated[list[str], Positional, Doc(' Filesystem locations or URLs. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases=None, prefix_name=False, constructor_factory=None)], clip: Annotated[bool | None, Doc(' Copy mimeogram to clipboard. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--clipboard', '--to-clipboard', prefix_name=None, constructor_factory=None)] | None = None, count_tokens: Annotated[bool | None, Doc(' Count total tokens in mimeogram. ')] | None = None, edit: Annotated[bool, Doc(' Spawn editor to capture introductory message. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-e', '--edit-message', prefix_name=None, constructor_factory=None)] = False, prepend_prompt: Annotated[bool, Doc(' Prepend mimeogram format instructions. ')] = False, recurse: Annotated[bool | None, Doc(' Recurse into directories. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-r', '--recurse-directories', '--recursive', prefix_name=None, constructor_factory=None)] | None = None, strict: Annotated[bool | None, Doc(' Fail on invalid contents? True, fail. False, skip. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--fail-on-invalid', prefix_name=None, constructor_factory=None)] | None = None, tokenizer: Annotated[Tokenizers | None, Doc(' Which tokenizer to use for counting? ')] | None = None, tokenizer_variant: Annotated[str | None, Doc(" Which tokenizer variant to use for counting?\n\n 'tiktoken': 'cl100k_base', 'o200k_base', etc....\n\n Not all tokenizers have variants.\n If not specified, then the default variant is used.\n ")] | None = None)¶
Bases:
CliCommandCreates mimeogram from filesystem locations or URLs.
- clip: Annotated[bool | None, Doc(' Copy mimeogram to clipboard. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--clipboard', '--to-clipboard', prefix_name=None, constructor_factory=None)]¶
- edit: Annotated[bool, Doc(' Spawn editor to capture introductory message. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-e', '--edit-message', prefix_name=None, constructor_factory=None)]¶
- recurse: Annotated[bool | None, Doc(' Recurse into directories. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='-r', '--recurse-directories', '--recursive', prefix_name=None, constructor_factory=None)]¶
- sources: Annotated[list[str], Positional, Doc(' Filesystem locations or URLs. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases=None, prefix_name=False, constructor_factory=None)]¶
- strict: Annotated[bool | None, Doc(' Fail on invalid contents? True, fail. False, skip. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--fail-on-invalid', prefix_name=None, constructor_factory=None)]¶
- tokenizer: Annotated[Tokenizers | None, Doc(' Which tokenizer to use for counting? ')]¶
- async mimeogram.create.create(auxdata: ~mimeogram.__.state.Globals, command: ~mimeogram.create.Command, *, editor: ~collections.abc.Callable[[], ~collections.abc.Coroutine[None, None, str]] = <function _edit_message>, clipcopier: ~collections.abc.Callable[[str], ~collections.abc.Coroutine[None, None, None]] = <function _copy_to_clipboard>, prompter: ~collections.abc.Callable[[~mimeogram.__.state.Globals], ~collections.abc.Coroutine[None, None, str]] = <function _acquire_prompt>) Never¶
Creates mimeogram.
Module mimeogram.differences¶
Content differences management.
- class mimeogram.differences.ConsoleDisplay(*, context_lines: int = 3, inline_threshold: int = 24)¶
Bases:
DifferencesDisplayDefault display of differences to console.
- class mimeogram.differences.ConsoleInteractor(*args, **kwargs)¶
Bases:
DifferencesInteractorDefault console-based interaction handler.
- async mimeogram.differences.select_segments(target: Target, revision: str, display: DifferencesDisplay | AbsentSingleton = absence.absent, interactor: DifferencesInteractor | AbsentSingleton = absence.absent) str¶
Selects which diff hunks to apply.
Module mimeogram.display¶
System pager interaction.
Module mimeogram.edit¶
System editor interaction.
Module mimeogram.exceptions¶
Family of exceptions for package API.
Omniexception: Base for all package exceptionsOmnierror: Base for all package errors
- exception mimeogram.exceptions.ContentAcquireFailure(location: str | Path)¶
Bases:
OmnierrorFailure to acquire content from location.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.ContentDecodeFailure(location: str | Path, charset: str)¶
Bases:
OmnierrorFailure to decode content as character set from location.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.ContentUpdateFailure(location: str | Path)¶
Bases:
OmnierrorFailure to update content at location.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.DifferencesProcessFailure(reason: str)¶
Bases:
OmnierrorFailure during diff processing.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.EditorFailure(cause: str | Exception)¶
Bases:
OmnierrorFailure while operating editor.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.LocationInvalidity(location: str | Path)¶
Bases:
OmnierrorInvalid location.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.MimeogramFormatEmpty¶
Bases:
OmnierrorAttempt to format empty mimeogram.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.MimeogramParseFailure(reason: str)¶
Bases:
OmnierrorFailure to parse mimeogram content.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.Omnierror¶
Bases:
Omniexception,ExceptionBase for error exceptions raised by package API.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.Omniexception¶
Bases:
BaseExceptionBase for all exceptions raised by package API.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.PagerFailure(cause: str | Exception)¶
Bases:
OmnierrorFailure while operating pager.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.ProgramAbsenceError(species: str)¶
Bases:
OmnierrorCould not discover valid editor.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.TextualMimetypeInvalidity(location: str | Path, mimetype: str)¶
Bases:
OmnierrorInvalid textual MIME type for content at location.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.TokenizerVariantInvalidity(name: str, variant: str)¶
Bases:
OmnierrorInvalid tokenizer variant.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.UrlSchemeNoSupport(url: str)¶
Bases:
OmnierrorUnsupported URL scheme.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
- exception mimeogram.exceptions.UserOperateCancellation(cause: BaseException)¶
Bases:
OmniexceptionOperation cancelled by user.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args¶
Module mimeogram.formatters¶
Formatting of mimeogram bundles.
Module mimeogram.interactions¶
User interactions and automations.
- class mimeogram.interactions.GenericInteractor(*, prompter: ~collections.abc.Callable[[~mimeogram.parts.Target, str, bool], str] = <function _prompt_action>, cdisplayer: ~collections.abc.Callable[[~mimeogram.parts.Target, str], ~collections.abc.Coroutine[None, None, None]] = <function _display_content>, ddisplayer: ~collections.abc.Callable[[~mimeogram.parts.Target, str], ~collections.abc.Coroutine[None, None, None]] = <function _display_differences>, editor: ~collections.abc.Callable[[~mimeogram.parts.Target, str], ~collections.abc.Coroutine[None, None, str]] = <function _edit_content>, sselector: ~collections.abc.Callable[[~mimeogram.parts.Target, str], ~collections.abc.Coroutine[None, None, str]] = <function _select_segments>, validator: ~collections.abc.Callable[[~mimeogram.parts.Target, str], None] = <function _validate_choice>)¶
Bases:
PartInteractorDefault console-based interaction handler.
- async mimeogram.interactions.interact(target: Target, interactor: PartInteractor | AbsentSingleton = absence.absent) tuple[Resolutions, str]¶
Performs interaction for part.
Module mimeogram.interfaces¶
Abstract bases and interfaces.
- class mimeogram.interfaces.DifferencesDisplay(*args, **kwargs)¶
Bases:
ProtocolConfiguration for content differences display.
Module mimeogram.parsers¶
Parsers for mimeograms and their constituents.
Module mimeogram.parts¶
Mimeogram parts.
- class mimeogram.parts.LineSeparators(value)¶
Bases:
EnumLine separators for various platforms.
- classmethod detect_bytes(content: bytes, limit=1024) LineSeparators | None¶
Detects newline characters in bytes array.
- classmethod normalize_universal(content: str) str¶
Normalizes all varieties of newline characters in text.
- CR = '\r'¶
- CRLF = '\r\n'¶
- LF = '\n'¶
- class mimeogram.parts.Part(*, location: str, mimetype: str, charset: str, linesep: LineSeparators, content: str)¶
Bases:
objectPart of mimeogram.
- linesep: LineSeparators¶
Module mimeogram.prompt¶
Mimeogram prompt text for LLMs.
- class mimeogram.prompt.Command(*, clip: Annotated[bool | None, Doc(' Copy prompt to clipboard. '), _ArgConfig(name=None, metavar=None, help=None, help_behavior_hint=None, aliases='--clipboard', '--to-clipboard', prefix_name=None, constructor_factory=None)] | None = None)¶
Bases:
CliCommandProvides LLM prompt text for mimeogram format.
Module mimeogram.tokenizers¶
Language model tokenizers.
- class mimeogram.tokenizers.Tiktoken(*, codec: Encoding)¶
Bases:
TokenizerTokenization via ‘tiktoken’ package.
- async classmethod from_variant(name: str | AbsentSingleton = absence.absent) Self¶
Produces instance from name of variant.
- codec: Encoding¶
Module mimeogram.updaters¶
File content updates.
- class mimeogram.updaters.Queue(*, updates: list[tuple[~mimeogram.parts.Part, ~pathlib.Path, str]] = <factory>, reverter: ~mimeogram.updaters.Reverter = <factory>)¶
Bases:
objectManages queued file updates for batch application.
- class mimeogram.updaters.Reverter(*, originals: dict[~pathlib.Path, str] = <factory>, revisions: list[~pathlib.Path] = <factory>)¶
Bases:
objectBackup and restore filesystem state.
- class mimeogram.updaters.ReviewModes(value)¶
Bases:
EnumControls how updates are reviewed and applied.
- Partitive = 'partitive'¶
- Silent = 'silent'¶
- async mimeogram.updaters.update(auxdata: Globals, parts: Sequence[Part], mode: ReviewModes, base: Path | AbsentSingleton = absence.absent, interactor: PartInteractor | AbsentSingleton = absence.absent, protector: Protector | AbsentSingleton = absence.absent) None¶
Updates filesystem locations from mimeogram.
- async mimeogram.updaters.update_part(auxdata: Globals, target: Target, mode: ReviewModes, interactor: PartInteractor | AbsentSingleton = absence.absent) tuple[Resolutions, str]¶
Updates filesystem location from mimeogram part.
Package mimeogram.fsprotect¶
A subpackage providing filesystem protection features to prevent dangerous modifications to sensitive paths.
Module mimeogram.fsprotect.cache¶
Cache for filesystem protection checks.
- class mimeogram.fsprotect.cache.Cache(*, rules: dict[Reasons, Rule], defaults_disablement: frozenset[str], rules_supercession: Dictionary[Path, tuple[frozenset[str], frozenset[str]]])¶
Bases:
ProtectorCache of protected paths and patterns for platform.
- class mimeogram.fsprotect.cache.Rule(*, paths: frozenset[Path], patterns: frozenset[str] = frozenset({}))¶
Bases:
objectRule for path protection.
- mimeogram.fsprotect.cache.discover_platform_locations(auxdata: Globals, rules: dict[Reasons, Rule]) None¶
Discovers system and user locations based on platform.
Module mimeogram.fsprotect.core¶
Core entities for filesystem protection.
- class mimeogram.fsprotect.core.Protector(*args, **kwargs)¶
Bases:
ProtocolFilesystem protection checker.
- class mimeogram.fsprotect.core.Reasons(value)¶
Bases:
EnumReasons why location may be protected.
- Concealment = 'Hidden file or directory'¶
- Credentials = 'Credentials or secrets location'¶
- CustomAddition = 'User-specified custom location'¶
- OsDirectory = 'Operating system directory'¶
- PlatformSensitive = 'Platform-sensitive location'¶
- UserConfiguration = 'User configuration directory'¶
- VersionControl = 'Version control internals'¶
Module mimeogram.fsprotect.home¶
Sensitive filesystem locations relative to user homes.
Module mimeogram.fsprotect.macos¶
Sensitive filesystem locations on macOS.
Module mimeogram.fsprotect.project¶
Sensitive filesystem locations relative to project directory.
Module mimeogram.fsprotect.unix¶
Sensitive filesystem locations on Unix/POSIX/Linux.
Module mimeogram.fsprotect.windows¶
Sensitive filesystem locations on Windows.