flaretool.shorturl package

Submodules

flaretool.shorturl.ShortUrlService module

Class for interacting with a short URL service.

Warning

This class may undergo updates and its usage may change in the near future.

class flaretool.shorturl.ShortUrlService.ShortUrlService

Bases: object

Class for interacting with a short URL service. WebAPI Wrapper class.

create(url: str, code: str | None = None, description: str | None = None, is_eternal: bool | None = None, is_active: bool | None = None) ShortUrlInfo

Create a new short URL.

Parameters:
  • url (str) – URL to shorten.

  • code (str | None) – Custom code for the short URL (default: None).

  • description (str | None) – Description of the short URL (default: None).

  • is_eternal (bool | None) – Whether the short URL is eternal (default: None).

  • is_active (bool | None) – Whether the short URL is active (default: None).

Returns:

Information about the created short URL.

Return type:

ShortUrlInfo

Raises:
delete(url_info: ShortUrlInfo) None

Delete a short URL.

Parameters:

url_info (ShortUrlInfo) – Updated information about the short URL.

Raises:
get(id: int | None = None) list[ShortUrlInfo]

Get informations about a short URL.

Parameters:

id (int | None) – ID of the short URL (default: None).

Returns:

Information about the short URL.

Return type:

list[ShortUrlInfo]

Raises:
get_qr_code_raw_data(url_info: ShortUrlInfo) bytes

Get QR Code raw data

Parameters:

url_info (ShortUrlInfo) – target information about the short URL.

Returns:

image bytes data.

Return type:

bytes

update(url_info: ShortUrlInfo) ShortUrlInfo

Update a short URL.

Parameters:

url_info (ShortUrlInfo) – Updated information about the short URL.

Returns:

Information about the updated short URL.

Return type:

ShortUrlInfo

Raises:

flaretool.shorturl.aio module

短縮URLサービスの非同期版クライアント。

同期版 ShortUrlService の各メソッドを asyncio.to_thread でワーカースレッドに委譲する薄いラッパーです。 イベントループをブロックせずに短縮URL APIを利用できます。

Warning

このクラスは更新される可能性があり、近い将来使用方法が変更される場合があります。

class flaretool.shorturl.aio.AsyncShortUrlService(_service: ShortUrlService | None = None)

Bases: object

短縮URLサービスの非同期版クラス。

同期版 ShortUrlService をラップし、各メソッドを asyncio.to_thread 経由で実行します。 非同期コンテキストマネージャー(async with)としても利用できます。

Examples

>>> async with AsyncShortUrlService() as svc:
...     info = await svc.create("https://example.com")
...     print(info.short_url)
async create(url: str, code: str | None = None, description: str | None = None, is_eternal: bool | None = None, is_active: bool | None = None) ShortUrlInfo

非同期版: 新しい短縮URLを作成する。

Parameters:
  • url (str) – 短縮対象のURL。

  • code (str | None) – 短縮URLのカスタムコード(デフォルト: None)。

  • description (str | None) – 短縮URLの説明(デフォルト: None)。

  • is_eternal (bool | None) – 無期限とするか(デフォルト: None)。

  • is_active (bool | None) – 有効とするか(デフォルト: None)。

Returns:

作成された短縮URLの情報。

Return type:

ShortUrlInfo

Examples

>>> async with AsyncShortUrlService() as svc:
...     info = await svc.create("https://example.com", code="abcd")
async delete(url_info: ShortUrlInfo) None

非同期版: 短縮URLを削除する。

Parameters:

url_info (ShortUrlInfo) – 削除対象の短縮URL情報。

Examples

>>> async with AsyncShortUrlService() as svc:
...     await svc.delete(url_info)
async get(id: int | None = None) list[ShortUrlInfo]

非同期版: 短縮URLの情報一覧を取得する。

Parameters:

id (int | None) – 短縮URLのID(デフォルト: None、全件取得)。

Returns:

短縮URLの情報リスト。

Return type:

list[ShortUrlInfo]

Examples

>>> async with AsyncShortUrlService() as svc:
...     infos = await svc.get()
async get_qr_code_raw_data(url_info: ShortUrlInfo) bytes

非同期版: QRコードの生データ(画像バイト列)を取得する。

Parameters:

url_info (ShortUrlInfo) – 対象の短縮URL情報。

Returns:

画像のバイトデータ。

Return type:

bytes

Examples

>>> async with AsyncShortUrlService() as svc:
...     raw = await svc.get_qr_code_raw_data(url_info)
async update(url_info: ShortUrlInfo) ShortUrlInfo

非同期版: 短縮URLの情報を更新する。

Parameters:

url_info (ShortUrlInfo) – 更新後の短縮URL情報。

Returns:

更新された短縮URLの情報。

Return type:

ShortUrlInfo

Examples

>>> async with AsyncShortUrlService() as svc:
...     updated = await svc.update(url_info)

flaretool.shorturl.errors module

Errors raised by the short URL service.

exception flaretool.shorturl.errors.ShortUrlAuthenticationError(message: str, author: str | None = None, response: int | None = None, data: Any = None)

Bases: ShortUrlError

exception flaretool.shorturl.errors.ShortUrlDataUpdateError(message: str, author: str | None = None, response: int | None = None, data: Any = None)

Bases: ShortUrlError

exception flaretool.shorturl.errors.ShortUrlError(message: str, author: str | None = None, response: int | None = None, data: Any = None)

Bases: FlareToolError

Base error for the short URL service.

exception flaretool.shorturl.errors.ShortUrlValidError(message: str, author: str | None = None, response: int | None = None, data: Any = None)

Bases: ShortUrlError

flaretool.shorturl.models module

Data models for the short URL service.

class flaretool.shorturl.models.ShortUrlInfo(*, id: int, url: str, title: str, code: str, tag: str | None = None, description: str | None = None, owner: str, is_active: bool, is_eternal: bool, limited_at: datetime | None = None, created_at: datetime, updated_at: datetime, short_url: str | None = None, qr_url: str | None = None)

Bases: BaseDataModel

code: str
created_at: datetime
description: str | None
id: int
is_active: bool
is_eternal: bool
limited_at: datetime | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

owner: str
qr_url: str | None
short_url: str | None
tag: str | None
title: str
updated_at: datetime
url: str

Module contents

class flaretool.shorturl.AsyncShortUrlService(_service: ShortUrlService | None = None)

Bases: object

短縮URLサービスの非同期版クラス。

同期版 ShortUrlService をラップし、各メソッドを asyncio.to_thread 経由で実行します。 非同期コンテキストマネージャー(async with)としても利用できます。

Examples

>>> async with AsyncShortUrlService() as svc:
...     info = await svc.create("https://example.com")
...     print(info.short_url)
async create(url: str, code: str | None = None, description: str | None = None, is_eternal: bool | None = None, is_active: bool | None = None) ShortUrlInfo

非同期版: 新しい短縮URLを作成する。

Parameters:
  • url (str) – 短縮対象のURL。

  • code (str | None) – 短縮URLのカスタムコード(デフォルト: None)。

  • description (str | None) – 短縮URLの説明(デフォルト: None)。

  • is_eternal (bool | None) – 無期限とするか(デフォルト: None)。

  • is_active (bool | None) – 有効とするか(デフォルト: None)。

Returns:

作成された短縮URLの情報。

Return type:

ShortUrlInfo

Examples

>>> async with AsyncShortUrlService() as svc:
...     info = await svc.create("https://example.com", code="abcd")
async delete(url_info: ShortUrlInfo) None

非同期版: 短縮URLを削除する。

Parameters:

url_info (ShortUrlInfo) – 削除対象の短縮URL情報。

Examples

>>> async with AsyncShortUrlService() as svc:
...     await svc.delete(url_info)
async get(id: int | None = None) list[ShortUrlInfo]

非同期版: 短縮URLの情報一覧を取得する。

Parameters:

id (int | None) – 短縮URLのID(デフォルト: None、全件取得)。

Returns:

短縮URLの情報リスト。

Return type:

list[ShortUrlInfo]

Examples

>>> async with AsyncShortUrlService() as svc:
...     infos = await svc.get()
async get_qr_code_raw_data(url_info: ShortUrlInfo) bytes

非同期版: QRコードの生データ(画像バイト列)を取得する。

Parameters:

url_info (ShortUrlInfo) – 対象の短縮URL情報。

Returns:

画像のバイトデータ。

Return type:

bytes

Examples

>>> async with AsyncShortUrlService() as svc:
...     raw = await svc.get_qr_code_raw_data(url_info)
async update(url_info: ShortUrlInfo) ShortUrlInfo

非同期版: 短縮URLの情報を更新する。

Parameters:

url_info (ShortUrlInfo) – 更新後の短縮URL情報。

Returns:

更新された短縮URLの情報。

Return type:

ShortUrlInfo

Examples

>>> async with AsyncShortUrlService() as svc:
...     updated = await svc.update(url_info)
class flaretool.shorturl.ShortUrlService

Bases: object

Class for interacting with a short URL service. WebAPI Wrapper class.

create(url: str, code: str | None = None, description: str | None = None, is_eternal: bool | None = None, is_active: bool | None = None) ShortUrlInfo

Create a new short URL.

Parameters:
  • url (str) – URL to shorten.

  • code (str | None) – Custom code for the short URL (default: None).

  • description (str | None) – Description of the short URL (default: None).

  • is_eternal (bool | None) – Whether the short URL is eternal (default: None).

  • is_active (bool | None) – Whether the short URL is active (default: None).

Returns:

Information about the created short URL.

Return type:

ShortUrlInfo

Raises:
delete(url_info: ShortUrlInfo) None

Delete a short URL.

Parameters:

url_info (ShortUrlInfo) – Updated information about the short URL.

Raises:
get(id: int | None = None) list[ShortUrlInfo]

Get informations about a short URL.

Parameters:

id (int | None) – ID of the short URL (default: None).

Returns:

Information about the short URL.

Return type:

list[ShortUrlInfo]

Raises:
get_qr_code_raw_data(url_info: ShortUrlInfo) bytes

Get QR Code raw data

Parameters:

url_info (ShortUrlInfo) – target information about the short URL.

Returns:

image bytes data.

Return type:

bytes

update(url_info: ShortUrlInfo) ShortUrlInfo

Update a short URL.

Parameters:

url_info (ShortUrlInfo) – Updated information about the short URL.

Returns:

Information about the updated short URL.

Return type:

ShortUrlInfo

Raises: