Skip to main content

A Python wrapper for the zNeitiz API

Project description

zNeitiz

Wrapper for zNeitiz API [source].

Install with pip install zneitiz

Or install from GitHub with pip install zneitiz@git+https://github.com/z03h/zNeitiz-Clienty@master.

Don't expect great things, pretty quick and dirty. The API is also low effort so don't expect much from it.

Minimum python version is probaby 3.9.

Sample images in the wiki.

Examples

import asyncio
import aiohttp

from zneitiz import NeitizClient, NeitizException, NeitizRatelimitException

image_url = '...'


async def main():

    print(zneitiz.__version__)

    # Use an already existing aiohttp.ClientSession.
    cs = aiohttp.ClientSession()
    znclient = NeitizClient(session=cs)
    # returns an awaitable `Route` that returns a `NeitizImage`.
    # `NeitizImage`s should be treated like an `io.BytesIO`
    # has `endpoint`, `content_type` and `extension` attributes
    # can access the Route used for the request with `route` attribute.
    try:
        route = znclient.sand(image_url)
        file = await route  # can also be shortened to await znclient.sand(image_url)
    except NeitizRatelimitException as e:
        # client will raise NeitizRatelimitException to prevent 429 errors
        print('ratelimit reset', e.ratelimit_reset)
    except NeitizHTTPException as e:
        # can get the status and message of other failed requests
        print(e.status, e.message)
    else:
        with open(f'{file.endpoint}.{file.extension}', 'wb') as f:
            data = file.read()
            f.write(data)


    # All image urls can be replace with file-like objects
    # such as BytesIO or opened files
    with open('path/to/image.png', 'rb') as image:
        data = image.read()
        new_data = await znclient.explode(io.BytesIO(data))

        image.seek(0)
        other_data = await znclient.explode(image)

    # NeitizClient should be closed if you do not pass in a session
    await znclient.close()


    # Use context manager to handle cleanup.
    # Can opt to pass `None` for session if you do not want to create a session
    async with NeitizClient(session=None) as znclient:
        # You can access `Route.url`, `Route.headers`, and `Route.json` for
        # manual requests or use with other libraries.
        route = znclient.sand(image_url)
        url: str = route.url
        headers: dict[str, str] = route.headers
        json_body: dict[str, any] = route.json

        import requests
        r = requests.post(url=url, headers=headers, json=json_body)


    # can use an async context manager with Route to handle the request manually
    async with NeitizClient() as znclient:
        async with znclient.sand(image_url) as response:
            headers = response.headers
            if response.ok:
                data = await response.read()
            else:
                print(response.status, response.message)



asyncio.run(main())

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

zneitiz-0.3.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zneitiz-0.3.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file zneitiz-0.3.1.tar.gz.

File metadata

  • Download URL: zneitiz-0.3.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for zneitiz-0.3.1.tar.gz
Algorithm Hash digest
SHA256 500077ffbad7311052746ed91e388502f2ed57515ab2813b0a76e08b73d078ae
MD5 1c4a6b9e7d3d7300f7a9bc0f807c822f
BLAKE2b-256 c5ece2d218dc7f8ad0cb9635de1177890db837348eabfc3aa6d94e19f1b77db9

See more details on using hashes here.

File details

Details for the file zneitiz-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: zneitiz-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for zneitiz-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ba75261e82aa3768dad591196e6e2da6de827150e5301a8bd37d53f9e0765b1
MD5 8514ec7dddf5492571c3bdbfb07742ef
BLAKE2b-256 7dc03b76d424ff823260aeb157086cd85b895fc08e722c0f51b71c24a24d254b

See more details on using hashes here.

Supported by

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