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

Accessing multiple fields asynchronously #54

Open
conceptofmind opened this issue Nov 1, 2024 · 0 comments
Open

Accessing multiple fields asynchronously #54

conceptofmind opened this issue Nov 1, 2024 · 0 comments

Comments

@conceptofmind
Copy link

conceptofmind commented Nov 1, 2024

Hello,

I greatly appreciate all of your work.

I was wondering if you had any thoughts on returning multiple fields asynchronously.

Say you have the data:

b'[{"recordType":"item","comments":[],"licence":{"name":"Attribution 4.0 International","shortName":"CC BY","uri":"https://creativecommons.org/licenses/by/4.0"},"dateModified":"2024-10-31T23:58:00Z}]'

Code snippet:

async def request(url, session):
    async with session.get(url) as response:
        status = response.status
        if status == HTTPStatus.OK:
            data = await response.read()
            print(data)
            parser = cysimdjson.JSONParser()
            contents = parser.parse_in_place(data)
            content_dict={
                "Record Type": contents.at_pointer("/0/recordType")
                "Comments": contents.at_pointer("/0/comments")
            }
        else:
            contents = None
        return content_dict, status

async def fetch_public_domain_images(url, session) -> AsyncGenerator:
    contents, status = await request(url, session)
    yield contents, status

From my understanding, returning a dict will lose the speed benefit? If so what is the best way to access multiple fields within scope (will segfault).

Thank you,

Enrico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant