Skip to content

Feature: add httpx verify config #209

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 7 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ github = GitHub(
user_agent="GitHubKit/Python",
follow_redirects=True,
timeout=None,
ssl_verify=True,
cache_strategy=None,
http_cache=True,
throttler=None,
Expand All @@ -34,6 +35,7 @@ config = Config(
user_agent="GitHubKit/Python",
follow_redirects=True,
timeout=httpx.Timeout(None),
ssl_verify=True,
cache_strategy=DEFAULT_CACHE_STRATEGY,
http_cache=True,
throttler=None,
Expand Down Expand Up @@ -70,6 +72,10 @@ The `follow_redirects` option is used to enable or disable the HTTP redirect fol

The `timeout` option is used to set the request timeout. You can pass a float, `None` or `httpx.Timeout` to this field. By default, the requests will never timeout. See [Timeout](https://www.python-httpx.org/advanced/timeouts/) for more information.

### `ssl_verify`

The `ssl_verify` option is used to customize the SSL certificate verification. By default, githubkit enables the SSL certificate verification. If you want to disable the SSL certificate verification, you can set this option to `False`. Or you can provide a custom ssl context to this option. See [SSL](https://www.python-httpx.org/advanced/ssl/) for more information.

### `cache_strategy`

The `cache_strategy` option defines how to cache the tokens or http responses. You can provide a githubkit built-in cache strategy or a custom one that implements the `BaseCacheStrategy` interface. By default, githubkit uses the `MemCacheStrategy` to cache the data in memory.
Expand Down
8 changes: 7 additions & 1 deletion githubkit/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence
from dataclasses import dataclass, fields
from typing import Any, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union
from typing_extensions import Self

import httpx
Expand All @@ -10,6 +10,9 @@
from .throttling import BaseThrottler, LocalThrottler
from .typing import RetryDecisionFunc

if TYPE_CHECKING:
import ssl


@dataclass(frozen=True)
class Config:
Expand All @@ -18,6 +21,7 @@ class Config:
user_agent: str
follow_redirects: bool
timeout: httpx.Timeout
ssl_verify: Union[bool, "ssl.SSLContext"]
cache_strategy: BaseCacheStrategy
http_cache: bool
throttler: BaseThrottler
Expand Down Expand Up @@ -104,6 +108,7 @@ def get_config(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
cache_strategy: Optional[BaseCacheStrategy] = None,
http_cache: bool = True,
throttler: Optional[BaseThrottler] = None,
Expand All @@ -117,6 +122,7 @@ def get_config(
build_user_agent(user_agent),
follow_redirects,
build_timeout(timeout),
ssl_verify,
build_cache_strategy(cache_strategy),
http_cache,
build_throttler(throttler),
Expand Down
11 changes: 10 additions & 1 deletion githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta, timezone
import time
from types import TracebackType
from typing import Any, Generic, Optional, TypeVar, Union, cast, overload
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar, Union, cast, overload

import anyio
import hishel
Expand Down Expand Up @@ -36,6 +36,9 @@
)
from .utils import UNSET

if TYPE_CHECKING:
import ssl

T = TypeVar("T")
A = TypeVar("A", bound="BaseAuthStrategy")
AS = TypeVar("AS", bound="BaseAuthStrategy")
Expand Down Expand Up @@ -81,6 +84,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional[BaseCacheStrategy] = None,
http_cache: bool = True,
throttler: Optional[BaseThrottler] = None,
Expand All @@ -100,6 +104,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional[BaseCacheStrategy] = None,
http_cache: bool = True,
throttler: Optional[BaseThrottler] = None,
Expand All @@ -119,6 +124,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional[BaseCacheStrategy] = None,
http_cache: bool = True,
throttler: Optional[BaseThrottler] = None,
Expand All @@ -137,6 +143,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
cache_strategy: Optional[BaseCacheStrategy] = None,
http_cache: bool = True,
throttler: Optional[BaseThrottler] = None,
Expand All @@ -155,6 +162,7 @@ def __init__(
user_agent=user_agent,
follow_redirects=follow_redirects,
timeout=timeout,
ssl_verify=ssl_verify,
cache_strategy=cache_strategy,
http_cache=http_cache,
throttler=throttler,
Expand Down Expand Up @@ -212,6 +220,7 @@ def _get_client_defaults(self):
},
"timeout": self.config.timeout,
"follow_redirects": self.config.follow_redirects,
"verify": self.config.ssl_verify,
}

# create sync client
Expand Down
5 changes: 5 additions & 0 deletions githubkit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .versions import RestVersionSwitcher, WebhooksVersionSwitcher

if TYPE_CHECKING:
import ssl

import httpx

from .auth import TokenAuthStrategy, UnauthAuthStrategy
Expand Down Expand Up @@ -74,6 +76,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional["BaseCacheStrategy"] = None,
http_cache: bool = True,
throttler: Optional["BaseThrottler"] = None,
Expand All @@ -93,6 +96,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional["BaseCacheStrategy"] = None,
http_cache: bool = True,
throttler: Optional["BaseThrottler"] = None,
Expand All @@ -112,6 +116,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
cache_strategy: Optional["BaseCacheStrategy"] = None,
http_cache: bool = True,
throttler: Optional["BaseThrottler"] = None,
Expand Down