Skip to content

Docs: add weakref warning #111

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

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ async with GitHub("<your_token_here>") as github:
repo: FullRepository = resp.parsed_data
```

> [!WARNING]
> Note that you should hold a strong reference to the githubkit client instance. Otherwise, githubkit client will fail to call the request.
> For example, you should not do this:
>
> ```python
> from githubkit import GitHub
>
> def get_client() -> GitHub:
> return GitHub()
>
> # This will cause error
> get_client().rest.repos.get("owner", "repo")
>
> # This is ok
> client = get_client()
> client.rest.repos.get("owner", "repo")
> ```

### Data Validation

As shown above, the response data is parsed and validated by accessing the `response.parsed_data` property. This ensures that the data type returned by the API is as expected and your code is safe to use it (with static type checking). But sometimes you may want to get the raw data returned by the API, such as when the schema is not correct. You can use the `response.text` property or `response.json()` method to get the raw data:
Expand Down