Skip to main content

A python wrapper for the rentry markdown service.

Project description

rentry.py

A python wrapper for the rentry markdown service.

This package allows for accessing the rentry API through the command line or as a module in your project.

Installation

rentry.py can be installed via pip:

pip install rentry.py

Or added to your project via uv:

uv add rentry.py

Command Line

The command interface offers every endpoint as terminal commands. Those commands and their arguments are detailed below.

Commands

  • help: Show this help message.
  • read: Get the raw markdown of a page with a SECRET_RAW_ACCESS_CODE set or if you provide an --auth-token.
    • rentry read <--page-id PAGE_ID> [--auth-token AUTH_TOKEN]
  • fetch: Fetch the data for a page you have the edit code for.
    • rentry fetch <--page-id PAGE_ID> <--edit-code EDIT_CODE>
  • exists: Check if a page exists.
    • rentry exists <--page-id PAGE_ID>
  • create: Create a new page.
    • rentry create <--markdown MARKDOWN> [--page-id PAGE_ID] [--edit-code EDIT_CODE] [--metadata METADATA]
  • update: Update a page you have the edit or modify code for.
    • rentry update <--page-id PAGE_ID> <--edit-code EDIT_CODE> [--new-page-id NEW_PAGE_ID] [--new-edit-code NEW_EDIT_CODE] [--new-modify-code NEW_MODIFY_CODE] [--markdown MARKDOWN] [--metadata METADATA] [--overwrite]
  • delete: Delete a page you have the edit code for.
    • rentry delete <--page-id PAGE_ID> <--edit-code EDIT_CODE>

Arguments

  • --page-id
  • --edit-code
    • When used with the update command this can be a modify code instead.
    • Modify codes start with m: and do not allow updating the edit or modify codes or deleting the page.
  • --auth-token
    • Auth tokens are acquired by contacting rentry support.
  • --new-page-id
    • Must be between 2 and 100 characters.
    • Must contain only latin letters, numbers, underscores and hyphens.
    • Will cause the existing modify code to reset if set.
  • --new-edit-code
    • Must be between 1 and 100 characters.
    • Can't start with m: as that is reserved for modify codes.
  • --new-modify-code
    • Must start with m: and be between 1 and 100 characters.
    • Provide m: to remove the modify code.
  • --markdown
    • Must be between 1 and 200,000 characters.
  • --metadata
    • A JSON string containing '{"string": "string"}' key-value pairs.
  • --overwrite
    • Whether to overwrite the existing markdown and metadata with the new values.
  • --base-url
    • The base URL to use.
    • Defaults to https://rentry.co but can be set to https://rentry.org.
    • All data is shared between the two domains.

Examples

  • rentry read --page-id py
  • rentry fetch --page-id py --edit-code pyEditCode
  • rentry exists --page-id py
  • rentry create --markdown "Hello, World!" --page-id py --edit-code pyEditCode
  • rentry delete --page-id py --edit-code pyEditCode --base-url "https://rentry.org"

Module

Basic

The module interface offers every endpoint as methods: read(), fetch(), exists(), create(), update(), and delete(). The read() method is an alias of the raw endpoint and the create() method is an alias of the new endpoint.

Instantiate a synchronous or asynchronous client to get started with rentry.py.

import asyncio

from rentry import RentryAsyncClient, RentryAsyncPage, RentrySyncClient, RentrySyncPage

sync_client = RentrySyncClient()
async_client = RentryAsyncClient()

You can customize the API base url by passing the client either "https://rentry.co" (default) or "https://rentry.org". Both domains work the same and all data is shared between them.

If one isn't passed, a CSRF token will be generated automatically by requesting one from rentry and it will be stored in csrf_token. The headers returned by the API imply these CSRF tokens last one year. It's unclear if anything will void them before that cutoff, however a new one can be generated at any time by calling client.refresh_session(). Alternatively, if you would like to generate a new CSRF token on each request, which would end up doubling the number of requests in total, you can pass use_session = False to the client.

You can then call the endpoints directly on the clients.

markdown: str = sync_client.read("py")
print(markdown)
# A python wrapper for the rentry markdown service.

Or, you can utilize the pages returned by fetch(), create(), and update().

py_page: RentrySyncPage = sync_client.fetch("py", "1234")
print(py_page.exists())
# True
py_page.delete()
print(py_page.exists())
# False
py_page.create()
print(py_page.exists())
# True

new_page: RentrySyncPage = sync_client.create("Hello, World!")
print(new_page.markdown)
# Hello, World!
print(new_page.page_url)
# https://rentry.co/<randomly_generated_string>
print(new_page.edit_code)
# <randomly_generated_string>

By default when you receive a RentrySyncPage or RentryAsyncPage their stats attribute will be empty. It's required to call fetch() to receive the extra page data. You can avoid doing this manually by passing fetch = True to create() or update().

print(new_page.stats.published_date)
# None
new_page.delete()
new_page.create(fetch = True)
print(new_page.stats.published_date)
# 2025-02-22 01:15:30

If you would like to identify yourself to the rentry API, you can do so by passing a user_agent to the client.

sync_client = RentrySyncClient(user_agent = "My Cool Project")

This will make your request appear as My-Cool-Project rentry.py/x.y.z (PyPI) to the API.

This is not required and at this time it is unknown if rentry will even make use of this information in any way.

Advanced

You can gain more control over your page style by making use of RentryPageMetadata. This is a mirror of the options listed at rentry/metadata-how. You can also see a basic example of how metadata works at rentry/metadata-example.

There are multiple ways to utilize the RentryPageMetadata object. The first is to build it through passing arguments. The second is through building it with a JSON string. The third is through building it with a dict.

from rentry import RentryPageMetadata, RentrySyncClient, RentrySyncPage

sync_client = RentrySyncClient()
metadata_one = RentryPageMetadata(PAGE_TITLE="This is an example.")
metadata_two = RentryPageMetadata.build('{"PAGE_TITLE": "This is an example."}')
metadata_three = RentryPageMetadata.build({"PAGE_TITLE": "This is an example."})

page: RentrySyncPage = sync_client.create("Hello, World", metadata = metadata_one)
print(page.metadata.PAGE_TITLE)
# This is an example.

The validations done to the metadata are extensive. They can be found in the docstring or in the tutorial link above. Most of rentry's validations have been mirrored in the class, meaning if you attempt to use invalid metadata an error will be raised before sending a request to the API. There are two exceptions to this.

The first is ACCESS_EASY_READ which requires an existing rentry url as its value. Checking that would require an API call of its own, so the class simply doesn't check it before sending the request to the API. The API will send a non-200 response if the URL does not exist, so an error is raised then instead.

The second is CONTENT_FONT which requires an existing font on Google Fonts. It's possible to query the Google Fonts API, however rentry itself also does not validate fonts. If an invalid value is used here it will silently fail to load on the page.

Auth Tokens

Auth tokens are how you access the raw endpoint through the read() method. No other endpoint requires auth tokens at this time.

You obtain an auth token by contacting rentry support with your request. There are two ways to make use of the auth token once acquired.

The first is through setting the SECRET_RAW_ACCESS_CODE metadata on a page. By doing so, anyone will be able to access the raw endpoint for your page. If you have an auth token, you can add it to your page like so: SECRET_RAW_ACCESS_CODE = auth_token. Once you save your changes the token will internally be obfuscated by rentry, so there is no need to worry about your token being stolen by someone else with edit access. However, as of 2025-02-22, there is a bug where if you save a SECRET_RAW_ACCESS_CODE to your page, even after you remove it users will be able to access the raw endpoint for your page. The only solution to stop it is to delete the page.

The second is by providing your auth token to the client as the auth_token argument. This will grant you access to any page's raw version regardless of if they have a SECRET_RAW_ACCESS_CODE set or not.

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

rentry_py-0.3.10.tar.gz (60.0 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-0.3.10-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rentry_py-0.3.10.tar.gz
  • Upload date:
  • Size: 60.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"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-0.3.10.tar.gz
Algorithm Hash digest
SHA256 77f880d7078355c2efc05edc02a1e57ad0440fea92603f5b3672f68a20453aa6
MD5 77a66aa1606e55f120715cea904a1474
BLAKE2b-256 f4ff5773d2101da4ad4f8d6b56b08e80586a71685c40d60f9d308d1de6cf2aa0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rentry_py-0.3.10-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"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-0.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 5358eb18067424a78936fe07889de1c31c7125b3436cabf357c40f3a53279ad3
MD5 a852dabfcd15ac07a2f5e7d4ee36d98d
BLAKE2b-256 3d4a5e3c350a293ff93e6c936d508fad6aabe37f4b52828ba94225236952dfab

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