Skip to content
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
8 changes: 4 additions & 4 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cliVersion": "4.29.0",
"cliVersion": "4.68.0",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "4.64.0",
"generatorVersion": "5.3.13",
"generatorConfig": {
"client": {
"class_name": "BaseNewscatcherApi",
Expand All @@ -10,6 +10,6 @@
"exported_filename": "client.py"
}
},
"originGitCommit": "bbd2054c67ad246b017399f96faf58cf6737bf01",
"sdkVersion": "2.0.2"
"originGitCommit": "c6c9411cf393ebdaab54b4265a5a8775d22986da",
"sdkVersion": "2.0.3"
}
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
Expand All @@ -67,7 +67,7 @@ jobs:
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The Newscatcher Python library provides convenient access to the Newscatcher API
- [Installation](#installation)
- [Reference](#reference)
- [Usage](#usage)
- [Environments](#environments)
- [Async Client](#async-client)
- [Exception Handling](#exception-handling)
- [Retrieving More Articles](#retrieving-more-articles)
Expand Down Expand Up @@ -53,6 +54,19 @@ client.search.post(
)
```

## Environments

This SDK allows you to configure different environments for API requests.

```python
from newscatcher import NewscatcherApi
from newscatcher.environment import NewscatcherApiEnvironment

client = NewscatcherApi(
environment=NewscatcherApiEnvironment.DEFAULT,
)
```

## Async Client

The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).
Expand Down
1,275 changes: 1,050 additions & 225 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dynamic = ["version"]

[tool.poetry]
name = "newscatcher-sdk"
version = "2.0.2"
version = "2.0.3"
description = ""
readme = "README.md"
authors = []
Expand All @@ -14,8 +14,6 @@ classifiers = [
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -39,16 +37,18 @@ packages = [
Repository = 'https://github.com/Newscatcher/newscatcher-python'

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.10"
aiohttp = { version = ">=3.10.0,<4", optional = true}
httpx = ">=0.21.2"
httpx-aiohttp = { version = "0.1.8", optional = true}
pydantic = ">= 1.9.2"
pydantic-core = ">=2.18.2"
pydantic-core = ">=2.18.2,<2.44.0"
typing_extensions = ">= 4.0.0"

[tool.poetry.group.dev.dependencies]
mypy = "==1.13.0"
pytest = "^7.4.0"
pytest-asyncio = "^0.23.5"
pytest = "^8.2.0"
pytest-asyncio = "^1.0.0"
pytest-xdist = "^3.6.1"
python-dateutil = "^2.9.0"
types-python-dateutil = "^2.9.0.20240316"
Expand All @@ -57,6 +57,9 @@ ruff = "==0.11.5"
[tool.pytest.ini_options]
testpaths = [ "tests" ]
asyncio_mode = "auto"
markers = [
"aiohttp: tests that require httpx_aiohttp to be installed",
]

[tool.mypy]
plugins = ["pydantic.mypy"]
Expand Down Expand Up @@ -88,3 +91,6 @@ section-order = ["future", "standard-library", "third-party", "first-party"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.extras]
aiohttp=["aiohttp", "httpx-aiohttp"]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
httpx>=0.21.2
pydantic>= 1.9.2
pydantic-core>=2.18.2
pydantic-core>=2.18.2,<2.44.0
typing_extensions>= 4.0.0
5 changes: 5 additions & 0 deletions src/newscatcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
sources,
subscription,
)
from ._default_clients import DefaultAioHttpClient, DefaultAsyncHttpxClient
from .aggregation_count import GetAggregationCountResponse, PostAggregationCountResponse
from .authors import GetAuthorsResponse, PostAuthorsResponse
from .client import AsyncNewscatcherApi, NewscatcherApi
Expand Down Expand Up @@ -177,6 +178,8 @@
"ContentSentimentMin": ".types",
"Countries": ".types",
"CustomTags": ".types",
"DefaultAioHttpClient": "._default_clients",
"DefaultAsyncHttpxClient": "._default_clients",
"Error": ".types",
"ExcludeDuplicates": ".types",
"FailedAggregationCountResponseDto": ".types",
Expand Down Expand Up @@ -332,6 +335,8 @@ def __dir__():
"ContentSentimentMin",
"Countries",
"CustomTags",
"DefaultAioHttpClient",
"DefaultAsyncHttpxClient",
"Error",
"ExcludeDuplicates",
"FailedAggregationCountResponseDto",
Expand Down
32 changes: 32 additions & 0 deletions src/newscatcher/_default_clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file was auto-generated by Fern from our API Definition.

import typing

import httpx

SDK_DEFAULT_TIMEOUT = 60

try:
import httpx_aiohttp # type: ignore[import-not-found]
except ImportError:

class DefaultAioHttpClient(httpx.AsyncClient): # type: ignore
def __init__(self, **kwargs: typing.Any) -> None:
raise RuntimeError(
"To use the aiohttp client, install the aiohttp extra: pip install newscatcher-sdk[aiohttp]"
)

else:

class DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
def __init__(self, **kwargs: typing.Any) -> None:
kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)


class DefaultAsyncHttpxClient(httpx.AsyncClient):
def __init__(self, **kwargs: typing.Any) -> None:
kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)
22 changes: 19 additions & 3 deletions src/newscatcher/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ def subscription(self):
return self._subscription


def _make_default_async_client(
timeout: typing.Optional[float],
follow_redirects: typing.Optional[bool],
) -> httpx.AsyncClient:
try:
import httpx_aiohttp # type: ignore[import-not-found]
except ImportError:
pass
else:
if follow_redirects is not None:
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)

if follow_redirects is not None:
return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
return httpx.AsyncClient(timeout=timeout)


class AsyncBaseNewscatcherApi:
"""
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
Expand Down Expand Up @@ -228,9 +246,7 @@ def __init__(
headers=headers,
httpx_client=httpx_client
if httpx_client is not None
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.AsyncClient(timeout=_defaulted_timeout),
else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
timeout=_defaulted_timeout,
logging=logging,
)
Expand Down
4 changes: 3 additions & 1 deletion src/newscatcher/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
from .http_client import AsyncHttpClient, HttpClient
from .http_response import AsyncHttpResponse, HttpResponse
from .jsonable_encoder import jsonable_encoder
from .jsonable_encoder import encode_path_param, jsonable_encoder
from .logging import ConsoleLogger, ILogger, LogConfig, LogLevel, Logger, create_logger
from .parse_error import ParsingError
from .pydantic_utilities import (
Expand Down Expand Up @@ -53,6 +53,7 @@
"convert_and_respect_annotation_metadata": ".serialization",
"convert_file_dict_to_httpx_tuples": ".file",
"create_logger": ".logging",
"encode_path_param": ".jsonable_encoder",
"encode_query": ".query_encoder",
"jsonable_encoder": ".jsonable_encoder",
"parse_obj_as": ".pydantic_utilities",
Expand Down Expand Up @@ -112,6 +113,7 @@ def __dir__():
"convert_and_respect_annotation_metadata",
"convert_file_dict_to_httpx_tuples",
"create_logger",
"encode_path_param",
"encode_query",
"jsonable_encoder",
"parse_obj_as",
Expand Down
4 changes: 2 additions & 2 deletions src/newscatcher/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def get_headers(self) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "newscatcher-sdk/2.0.2",
"User-Agent": "newscatcher-sdk/2.0.3",
"X-Fern-Language": "Python",
"X-Fern-Runtime": f"python/{platform.python_version()}",
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
"X-Fern-SDK-Name": "newscatcher-sdk",
"X-Fern-SDK-Version": "2.0.2",
"X-Fern-SDK-Version": "2.0.3",
**(self.get_custom_headers() or {}),
}
headers["x-api-token"] = self.api_key
Expand Down
Loading
Loading