Skip to main content

Asynchronous client for https://rentry.co/ (https://rentry.org/)

Project description

aiorentry

Asynchronous API client for rentry.co (mirror: rentry.org)

GitHub Actions Workflow Status codecov PyPI - Version GitHub License

About

This package allows you to interact with the rentry.co (or rentry.org) service.

Rentry.co is a markdown pastebin and publishing service that offers features such as previews, custom URLs, and editing.

Please note that this library is not developed by the official authors of rentry.co. It replicates the functionality of the official console utility, but provides it as an asynchronous API client. With this package you can manage your pages: create, edit and delete, as well as get data in text, PNG or PDF formats. All directly from your asynchronous Python application.

Installation

pip install aiorentry

Setup client

You can setup client in 2 ways:

As classic object

[!CAUTION] If you prefer the classic way, you should call await client.setup() during initialization and await client.close() during completion

import asyncio

from aiorentry.client import Client


async def main():
    client = Client('https://rentry.co')
    await client.setup()

    # Your code here

    await client.close()


asyncio.run(main())

As async context manager

import asyncio

from aiorentry.client import Client


async def main():
    async with Client('https://rentry.co') as client:
        # Your code here


asyncio.run(main())

Examples

Create new page

...
# Create new page
page = await client.new_page(
    '## Hello world from awesome API',
)

print(page)
...
Page(url='m2e2wpe8', edit_code='hUHeRUei', text='## Hello world from awesome API')
...
# Create new page with custom url and edit_code
awesome_page = await client.new_page(
    '## Hello world from awesome API',
    url='awesome-url',
    edit_code='qwerty=)'
)

print(awesome_page)
...
Page(url='awesome-url', edit_code='qwerty=)', text='## Hello world from awesome API')

Edit page

...
# Edit page
await client.edit_page(
    '### Updated Hello world',
    url='awesome-url',
    edit_code='qwerty=)',
)
...

Delete page

...
# Delete page
await client.delete_page(
    url='awesome-url',
    edit_code='qwerty=)',
)
...

Get raw page text

...
# Get raw content
content = await client.raw('awesome-url')
print(content)
...
### Updated Hello world

Get PDF file

...
# Get PDF
with open('page.pdf', mode='wb') as fp:
    fp.write(await client.pdf(page.url))
...

Get PNG

...
with open('page.png', mode='wb') as fp:
    fp.write(await client.png(page.url))
...

Custom ClientSession

[!NOTE] By default, a new instance of aiohttp.ClientSession will be created automatically. So normally you don't need to worry about this.

If you don't want to automatically create the session object inside the client, you can pass an existing aiohttp.ClientSession to the client constructor.

[!CAUTION] If you pass an existing session object to the client constructor, then you should care about releasing resources yourself.
The session will not be closed automatically! Even if the asynchronous context manager was used.

from aiohttp import ClientSession, TCPConnector
from aiorentry.client import Client

connector = TCPConnector(
    limit=5,  # Just for example
)

session = ClientSession(
    connector=connector,
)


async with Client('https://rentry.co', session=session) as client:
    # Your code here

async with session.get(...) as response:
    # You can still use this session object

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

aiorentry-0.1.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

aiorentry-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file aiorentry-0.1.2.tar.gz.

File metadata

  • Download URL: aiorentry-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.13 Linux/6.8.0-1014-azure

File hashes

Hashes for aiorentry-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a52893c006a9b4ab9599c0f5323bb15e3b310bf700572d7a3eddc02e9aa4c70
MD5 e22012ef72317a591c9828361b7b178e
BLAKE2b-256 ba673adcfb76e556528d44bb2a7a91c8b52e19322d43acaf43962747b9379e38

See more details on using hashes here.

File details

Details for the file aiorentry-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aiorentry-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.13 Linux/6.8.0-1014-azure

File hashes

Hashes for aiorentry-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e8658e1b71ea1497214837d0bc21c1070ff1e99fad0171d94da63e1734480f6
MD5 919618845d050d0cd3286c0c329fd6a1
BLAKE2b-256 d9f6df6cedc4c8bd429f183700497c72259558abbb582d0aec6a74fc0ff4b6d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page