<@ULVA73B9P> I'm trying to use the `prefect-client...
# ask-marvin
g
@Marvin I'm trying to use the
prefect-client
package. Trying to run the example
Copy code
from prefect.client.orchestration import get_client


async def query_api():
    async with get_client() as client:
        limits = await client.read_concurrency_limits(limit=10, offset=0)
        print(limits)


query_api()
throws the following error
ImportError: cannot import name 'schemas' from 'prefect.server' (unknown location)
m
thought for 81.7 seconds
Here's what I recommend: 1. First, make sure you have the correct dependencies installed:
Copy code
bash
pip install prefect-client
2. The correct way to use the client in Prefect 3.x is:
Copy code
python
from prefect.client import get_client

async def query_api():
    async with get_client() as client:
        limits = await client.read_concurrency_limits(limit=10, offset=0)
        print(limits)

# To run the async function:
import asyncio
asyncio.run(query_api())
Key changes from your original code: 1. Import
get_client
directly from
prefect.client
instead of
prefect.client.orchestration
2. Add the
asyncio.run()
wrapper to execute the async function If you're still getting the error after making these changes, please try the following: 1. Check your Prefect version:
Copy code
bash
pip show prefect
pip show prefect-client
2. Make sure there are no conflicting installations:
Copy code
bash
pip uninstall prefect prefect-client
pip install -U prefect prefect-client
The error you're seeing suggests there might be an issue with the installation or version compatibility. The
schemas
import error typically occurs when there's a mismatch between the installed packages or when the installation is incomplete. Let me know if you still encounter issues after trying these solutions, and we can investigate further.
g
@Marvin
Copy code
import asyncio

from prefect.client import get_client


async def main():
    async with get_client() as client:
        response = await client.hello()
        print(response.json()) # 👋

asyncio.run(main())
still throws an error. Install prefect and prefect-client defeats the purpose of the client only package no?
m
Error: No module named 'prefect_client'
🔧 Using:
explore_module_offerings
📊 Tools used: •
explore_module_offerings
(8x) •
get_latest_prefect_release_notes
(4x) •
read_github_issues
(4x) •
research_prefect_topic
(4x) •
review_common_3x_gotchas
(4x) •
search_prefect_3x_docs
(4x)
g
@Bianca Hoch Any chance you can help here? Marvin crashed!
For anyone hitting this error. It's simply that if prefect can't find a remote config (in all the ways explained in the docs so either
~/.prefect
or env vars for example), prefect will try to run a local prefect server. And obviously running local server with just the client package fails! I fixed my container by setting the URL And key env vars (properly this time)