Skip to main content

A Python wrapper for the zNeitiz API

Project description

zNeitiz

Wrapper for zNeitiz API.

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.0.tar.gz (19.3 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.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zneitiz-0.3.0.tar.gz
  • Upload date:
  • Size: 19.3 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.0.tar.gz
Algorithm Hash digest
SHA256 2b3e4d563a976d561060cc174d48821dbaedf82b10365e7e9f5c68c01e895b57
MD5 1d421ad4df3b37c3d460ce4adab2a2c2
BLAKE2b-256 92ce05d8cf921c6f40dcdf40626032b0857810601af252ef43aa50af11c9f5e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zneitiz-0.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 621452207005f6758f24c07391b5a57d75a4c53c5280cb028a35e86ef2c76220
MD5 65a7e9cb8d9361bb5ffb0d476a3b4389
BLAKE2b-256 58bab327a33a51187c35824510677bd01f05f4c4c5679077ab3e971f3e1cafc7

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