Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify extract syntax #9

Open
Gallaecio opened this issue May 13, 2022 · 1 comment · May be fixed by #12
Open

Simplify extract syntax #9

Gallaecio opened this issue May 13, 2022 · 1 comment · May be fixed by #12
Assignees
Labels
enhancement New feature or request

Comments

@Gallaecio
Copy link
Contributor

What about simplifying

import asyncio
from base64 import b64decode

from zyte_api.aio.client import AsyncClient

async def main():
    client = AsyncClient()
    api_response = await client.request_raw(
        {
            'url': 'https://toscrape.com',
            'httpResponseBody': True,
        }
    )
    http_response_body: bytes = b64decode(
        api_response['httpResponseBody']
    )

asyncio.run(main())

as

import asyncio

from zyte_api.aio.client import AsyncClient

async def main():
    client = AsyncClient()
    api_response = await client.extract(
        url='https://toscrape.com',
        http_response_body=True,
    )
    http_response_body: bytes = api_response.http_response_body

asyncio.run(main())
@Gallaecio Gallaecio added the enhancement New feature or request label May 13, 2022
@BurnzZ
Copy link
Member

BurnzZ commented May 17, 2022

+1 on this.

I like this idea as this interface gives us type annotations to statically validate the parameters for the call. It also removes the effort of decoding the base64 body.

@Gallaecio Gallaecio self-assigned this May 17, 2022
@Gallaecio Gallaecio linked a pull request May 17, 2022 that will close this issue
3 tasks
@Gallaecio Gallaecio changed the title Simplify syntax Simplify extract syntax Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants