Skip to main content

rentry.py

PyPI Python License

A typed synchronous and asynchronous Python client for the Rentry Markdown publishing service.

Installation

pip install rentry.py

Or with uv:

uv add rentry.py

Library Usage

from rentry import Client

with Client() as client:
    created = client.create(
        "# Hello\n",
        slug="my-page",
        metadata={"PAGE_TITLE": "Hello!"},
    )

    print(created.url)
    print(created.edit_code)

    client.update(
        created.slug,
        created.edit_code,
        text="# Updated\n",
        metadata={"PAGE_DESCRIPTION": "An updated page!"},
    )

    page = client.fetch(created.slug, created.edit_code)
    print(page.text)
import asyncio

from rentry import AsyncClient


async def main() -> None:
    async with AsyncClient() as client:
        created = await client.create("# Hello!\n")
        page = await client.fetch(created.slug, created.edit_code)
        print(page.url)


asyncio.run(main())

Operations

  • create(text, *, metadata=UNSET, slug=None, edit_code=None) -> CreatedPage
  • fetch(slug, edit_code) -> Page
  • exists(slug) -> bool
  • raw(slug, *, access_code=None) -> str
  • update(...) -> None for partial, non-destructive upserts
  • replace(..., text=..., metadata=...) -> None for explicit full replacement
  • delete(slug, edit_code) -> None

Every operation accepts either a bare slug or a full https://rentry.co/https://rentry.org page URL. Pass domain="rentry.org" to Client or AsyncClient to use that domain instead of rentry.co.

Safe Updates And Explicit Replacement

update() always sends Rentry's upsert mode. Omitted text and metadata remain unchanged, an empty text string clears the page text, and a metadata value of None removes that option.

client.update(
    "my-page",
    "edit-code",
    metadata={
        "PAGE_TITLE": "New Title",
        "PAGE_DESCRIPTION": None,
    },
)

Use replace() when you intentionally want to replace the entire document. It requires both text and metadata, including when either is empty, so an omitted argument cannot silently clear a page.

client.replace("my-page", "edit-code", text="", metadata={})

Previously set SECRET_* metadata is protected by Rentry. Pass allow_secret_metadata_changes=True only when an update should be allowed to change or remove those values.

Set new_modify_code=None in update() to remove a modify code. New modify codes must begin with m:. A modify code can update content and metadata, but the client rejects attempts to rotate the slug or codes with one. Deletion always requires the full edit code.

Metadata

Known metadata keys are available through the Metadata TypedDict:

from rentry import Metadata

metadata: Metadata = {
    "PAGE_TITLE": "Example",
    "OPTION_DISABLE_VIEWS": True,
    "CONTENT_TEXT_COLOR": ["black", "white"],
}

Mappings, JSON object strings, and Rentry's newline-separated KEY = value syntax are accepted. Unknown string keys are passed through deliberately so newly added Rentry options work before the next library release. Detailed option validation remains server-authoritative. See Rentry's metadata reference.

Errors

All library exceptions derive from RentryError. Local input errors use InvalidSlugError, InvalidEditCodeError, and InvalidMetadataError. Connection failures use TransportError, malformed server responses use ProtocolError, and documented Rentry application statuses map to structured APIError subclasses:

  • ValidationError (400)
  • AccessDeniedError (403)
  • NotFoundError (404)
  • MethodNotAllowedError (405)
  • RateLimitError (429)
  • ServiceUnavailableError (503)

APIError exposes the original status, content, and errors fields.

Session Injection

Pass an existing niquests.Session or niquests.AsyncSession through session= to integrate with application-owned transport configuration. Injected sessions are never closed by the client. Sessions created by the client are closed by close()/aclose() or the context manager.

Command Line

The installed rentry command provides the same service operations:

rentry create "# Hello"
rentry create --file page.md --metadata-file metadata.json --slug my-page
rentry fetch my-page --edit-code EDIT_CODE
rentry exists my-page
rentry raw my-page --access-code ACCESS_CODE
rentry update my-page --edit-code EDIT_CODE --text "# Updated"
rentry replace my-page --edit-code EDIT_CODE --file page.md --metadata '{}'
rentry delete my-page --edit-code EDIT_CODE

Create and fetch results are JSON, mutation success is {"ok": true}, and errors go to stderr with a nonzero exit status. create, update, and replace support UTF-8 files and stdin. Use rentry --help or rentry COMMAND --help for all options.

Global options such as --domain and --timeout go before the command:

rentry --domain rentry.org --timeout 15 exists my-page

Development

Install the locked development environment and run the complete local gate:

uv sync --frozen
uv run python scripts/verify.py

The verifier compiles every Python file, enforces custom styling, checks Ruff formatting and lint, runs strict Pyright, and executes the test suite.

Download files

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

Source Distribution

rentry_py-1.0.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

rentry_py-1.0.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file rentry_py-1.0.0.tar.gz.

File metadata

  • Download URL: rentry_py-1.0.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rentry_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91994207ac0479f4aac3a53b36316d7cdf43e15198eea6dabc934ad733fdf16f
MD5 b751a336d4795825ad77872362285643
BLAKE2b-256 8af1b968d95f6341cd53ac3fa1d7234555020b001ce49ff73e25c3435fed9258

See more details on using hashes here.

File details

Details for the file rentry_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rentry_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rentry_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac0e985b2d672e1f1ba6adc9d4438f798843173a4aa465879f6fa6b10dfc51c5
MD5 c0049878f93510c2f53745b6da5b46b3
BLAKE2b-256 b0fffa8c40e3f9391c68059443c05a268cc5ba0e5307bbd6dd296a267d71d4f0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.3.10

2 files

0.3.9

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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