Skip to main content

Trace.moe python wrapper

Project description

TraceMoePY

Codacy Badge PyPI version Downloads Github Actions Code style

Install

  • Install using pip: pip install tracemoepy

Examples

  • All the examples below are after this piece of code:
import tracemoepy
tracemoe = tracemoepy.tracemoe.TraceMoe()
  • You can search image like:
result = tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
print(result.prettify())
print(f'{result.docs[0].title}')
  • Or if you provide base64 encoded image:
print(tracemoe.search(image, encode=False))
  • Or if you want to just provide the image, The wrapper will encode image using base64:
print(tracemoe.search('a.jpg', encode=True))
  • Natural Preview:
output = tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
output.docs[0].save('preview.mp4', mute = False) # True for silent
  • Save Natural preview (Method 2)
output = tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
video = tracemoe.natural_preview(output)
with open('preview.mp4', 'wb') as f:
  f.write(video)
  • Save Image Preview
from tracemoepy.helpers.constants import IMAGE_PREVIEW
output = tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
output.docs[0].save(save_path = 'preview.png', preview_path = IMAGE_PREVIEW)
  • Image Preview (Method 2)
output = tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
tracemoe.image_preview(output) # Gives content
  • You can do help(method_name) to get more info about the given method
help(tracemoe.search)

Asyncio

import tracemoepy
import asyncio
# It recommended is you provide your own aiohttp session as
# tracemoepy will NOT close the session, You can access the session
# like: tracemoe.aio_session, To provide own aiohttp session you can just do
# tracemoe.AsyncTrace(session = your_session)
tracemoe = tracemoepy.AsyncTrace()
async def anything():
   return await tracemoe.search('https://trace.moe/img/flipped-good.jpg', is_url = True)
loop = asyncio.get_event_loop()
loop.run_until_complete(anything())

Errors

  • TooManyRequests: Raised when API Limit is reached or Too many requests in short period of time.
  • EntityTooLarge: Raised when image size is greater than max size of 10MB.
  • ServerError: Raised when Something wrong with the trace.moe server or Image provided was malformed.
  • InvalidToken: Raised when Invalid token was provided.
  • EmptyImage: Raised when Image provided was empty.
  • InvalidPath: Invalid path was given, This is only raised by .save(...) method
  • All these errors are located at tracemoepy.errors, Example of handling Exception:
from tracemoepy.errors import TooManyRequests

try:
  # Do something
except TooManyRequests as t:
  print(t)
  # Do something if error

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

tracemoepy-3.8.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file tracemoepy-3.8.tar.gz.

File metadata

  • Download URL: tracemoepy-3.8.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.3

File hashes

Hashes for tracemoepy-3.8.tar.gz
Algorithm Hash digest
SHA256 cee3b8504056883370a5c5582d9b62d216322670594d77b741d8fabf45bd9ea1
MD5 143830cbbf7c603f9ec2be6c151a02bd
BLAKE2b-256 81f344c6f5a764273c0d2a744d2f2d78cee925667c1825f6cd5ce77cedb6a049

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