aiorentry


Nameaiorentry JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/froosty/aiorentry
SummaryAsynchronous client for https://rentry.co/ (https://rentry.org/)
upload_time2024-08-05 21:58:09
maintainerNone
docs_urlNone
authorfroosty
requires_python<4.0,>=3.10
licenseMIT
keywords markdown pastebin rentry
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiorentry

Asynchronous API client for [rentry.co](https://rentry.co) (mirror: [rentry.org](https://rentry.org))

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/froosty/aiorentry/lint_and_test.yml)
[![codecov](https://codecov.io/gh/froosty/aiorentry/graph/badge.svg?token=FJBRTOQ2HR)](https://codecov.io/gh/froosty/aiorentry)
[![PyPI - Version](https://img.shields.io/pypi/v/aiorentry)](https://pypi.org/project/aiorentry/)
![GitHub License](https://img.shields.io/github/license/froosty/aiorentry)

## About

This package allows you to interact with the [rentry.co](https://rentry.co) (or [rentry.org](https://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](https://github.com/radude/rentry), 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

```bash
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

```python
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

```python
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

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

print(page)
...
```

```bash
Page(url='m2e2wpe8', edit_code='hUHeRUei', text='## Hello world from awesome API')
```

```python
...
# 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)
...
```

```bash
Page(url='awesome-url', edit_code='qwerty=)', text='## Hello world from awesome API')
```

### Edit page

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

### Delete page

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

### Get raw page text

```python
...
# Get raw content
content = await client.raw('awesome-url')
print(content)
...
```

```
### Updated Hello world
```

### Get PDF file

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

### Get PNG

```python
...
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.

```python
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

```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/froosty/aiorentry",
    "name": "aiorentry",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "markdown, pastebin, rentry",
    "author": "froosty",
    "author_email": "froosty.gh@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/12/4e/baa80c1ea6fb143af6e568d655f9d96489726817ab90ffae799986eb48ff/aiorentry-0.1.1.tar.gz",
    "platform": null,
    "description": "# aiorentry\n\nAsynchronous API client for [rentry.co](https://rentry.co) (mirror: [rentry.org](https://rentry.org))\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/froosty/aiorentry/lint_and_test.yml)\n[![codecov](https://codecov.io/gh/froosty/aiorentry/graph/badge.svg?token=FJBRTOQ2HR)](https://codecov.io/gh/froosty/aiorentry)\n[![PyPI - Version](https://img.shields.io/pypi/v/aiorentry)](https://pypi.org/project/aiorentry/)\n![GitHub License](https://img.shields.io/github/license/froosty/aiorentry)\n\n## About\n\nThis package allows you to interact with the [rentry.co](https://rentry.co) (or [rentry.org](https://rentry.org)) service.\n\nRentry.co is a markdown pastebin and publishing service that offers features such as previews, custom URLs, and editing.\n\n**Please note** that this library is not developed by the official authors of rentry.co. It replicates the functionality of the [official console utility](https://github.com/radude/rentry), 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.\n\n## Installation\n\n```bash\npip install aiorentry\n```\n\n## Setup client\n\nYou can setup client in 2 ways:\n\n### As classic object\n\n> [!CAUTION]\n> If you prefer the classic way, you should call `await client.setup()` during initialization and `await client.close()` during completion\n\n```python\nimport asyncio\n\nfrom aiorentry.client import Client\n\n\nasync def main():\n    client = Client('https://rentry.co')\n    await client.setup()\n\n    # Your code here\n\n    await client.close()\n\n\nasyncio.run(main())\n```\n\n### As async context manager\n\n```python\nimport asyncio\n\nfrom aiorentry.client import Client\n\n\nasync def main():\n    async with Client('https://rentry.co') as client:\n        # Your code here\n\n\nasyncio.run(main())\n```\n\n## Examples\n\n### Create new page\n\n```python\n...\n# Create new page\npage = await client.new_page(\n    '## Hello world from awesome API',\n)\n\nprint(page)\n...\n```\n\n```bash\nPage(url='m2e2wpe8', edit_code='hUHeRUei', text='## Hello world from awesome API')\n```\n\n```python\n...\n# Create new page with custom url and edit_code\nawesome_page = await client.new_page(\n    '## Hello world from awesome API',\n    url='awesome-url',\n    edit_code='qwerty=)'\n)\n\nprint(awesome_page)\n...\n```\n\n```bash\nPage(url='awesome-url', edit_code='qwerty=)', text='## Hello world from awesome API')\n```\n\n### Edit page\n\n```python\n...\n# Edit page\nawait client.edit_page(\n    '### Updated Hello world',\n    url='awesome-url',\n    edit_code='qwerty=)',\n)\n...\n```\n\n### Delete page\n\n```python\n...\n# Delete page\nawait client.delete_page(\n    url='awesome-url',\n    edit_code='qwerty=)',\n)\n...\n```\n\n### Get raw page text\n\n```python\n...\n# Get raw content\ncontent = await client.raw('awesome-url')\nprint(content)\n...\n```\n\n```\n### Updated Hello world\n```\n\n### Get PDF file\n\n```python\n...\n# Get PDF\nwith open('page.pdf', mode='wb') as fp:\n    fp.write(await client.pdf(page.url))\n...\n```\n\n### Get PNG\n\n```python\n...\nwith open('page.png', mode='wb') as fp:\n    fp.write(await client.png(page.url))\n...\n```\n\n## Custom ClientSession\n\n> [!NOTE]\n> By default, a new instance of `aiohttp.ClientSession` will be created automatically. So normally you don't need to worry about this.\n\nIf you don't want to automatically create the session object inside the client, you can pass an existing `aiohttp.ClientSession` to the client constructor.\n\n> [!CAUTION]\n> If you pass an existing session object to the client constructor, then you should care about releasing resources yourself. \\\n> **The session will not be closed automatically!** Even if the asynchronous context manager was used.\n\n```python\nfrom aiohttp import ClientSession, TCPConnector\nfrom aiorentry.client import Client\n\nconnector = TCPConnector(\n    limit=5,  # Just for example\n)\n\nsession = ClientSession(\n    connector=connector,\n)\n\n\nasync with Client('https://rentry.co', session=session) as client:\n    # Your code here\n\nasync with session.get(...) as response:\n    # You can still use this session object\n\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous client for https://rentry.co/ (https://rentry.org/)",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/froosty/aiorentry",
        "Repository": "https://github.com/froosty/aiorentry"
    },
    "split_keywords": [
        "markdown",
        " pastebin",
        " rentry"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2252a8018777a59bb6c85fefae5276134ad5f25f6bee638b9e0560cb0ce4663c",
                "md5": "888efbcdb3e803a72bd84af621b43efc",
                "sha256": "50558b54f1c40b1057467f013fbabcb707065958ea83c91bb6085a690d35916f"
            },
            "downloads": -1,
            "filename": "aiorentry-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "888efbcdb3e803a72bd84af621b43efc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5134,
            "upload_time": "2024-08-05T21:58:08",
            "upload_time_iso_8601": "2024-08-05T21:58:08.208039Z",
            "url": "https://files.pythonhosted.org/packages/22/52/a8018777a59bb6c85fefae5276134ad5f25f6bee638b9e0560cb0ce4663c/aiorentry-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "124ebaa80c1ea6fb143af6e568d655f9d96489726817ab90ffae799986eb48ff",
                "md5": "66727637586a5028b3462b13e82ce499",
                "sha256": "695a2d5cbf999d12e0c89f100fdcf01919256b57eef609c3e9961f9d4059c7c8"
            },
            "downloads": -1,
            "filename": "aiorentry-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "66727637586a5028b3462b13e82ce499",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4768,
            "upload_time": "2024-08-05T21:58:09",
            "upload_time_iso_8601": "2024-08-05T21:58:09.499341Z",
            "url": "https://files.pythonhosted.org/packages/12/4e/baa80c1ea6fb143af6e568d655f9d96489726817ab90ffae799986eb48ff/aiorentry-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-05 21:58:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "froosty",
    "github_project": "aiorentry",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiorentry"
}
        
Elapsed time: 0.56969s