aiorentry


Nameaiorentry JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/froosty/aiorentry
SummaryAsynchronous client for https://rentry.co/ (https://rentry.org/)
upload_time2024-10-01 13:55:40
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/ba/67/3adcfb76e556528d44bb2a7a91c8b52e19322d43acaf43962747b9379e38/aiorentry-0.1.2.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.2",
    "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": "d9f6df6cedc4c8bd429f183700497c72259558abbb582d0aec6a74fc0ff4b6d7",
                "md5": "919618845d050d0cd3286c0c329fd6a1",
                "sha256": "0e8658e1b71ea1497214837d0bc21c1070ff1e99fad0171d94da63e1734480f6"
            },
            "downloads": -1,
            "filename": "aiorentry-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "919618845d050d0cd3286c0c329fd6a1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5132,
            "upload_time": "2024-10-01T13:55:39",
            "upload_time_iso_8601": "2024-10-01T13:55:39.619485Z",
            "url": "https://files.pythonhosted.org/packages/d9/f6/df6cedc4c8bd429f183700497c72259558abbb582d0aec6a74fc0ff4b6d7/aiorentry-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba673adcfb76e556528d44bb2a7a91c8b52e19322d43acaf43962747b9379e38",
                "md5": "e22012ef72317a591c9828361b7b178e",
                "sha256": "7a52893c006a9b4ab9599c0f5323bb15e3b310bf700572d7a3eddc02e9aa4c70"
            },
            "downloads": -1,
            "filename": "aiorentry-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e22012ef72317a591c9828361b7b178e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4768,
            "upload_time": "2024-10-01T13:55:40",
            "upload_time_iso_8601": "2024-10-01T13:55:40.874242Z",
            "url": "https://files.pythonhosted.org/packages/ba/67/3adcfb76e556528d44bb2a7a91c8b52e19322d43acaf43962747b9379e38/aiorentry-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-01 13:55:40",
    "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: 4.67132s