Skip to content

Commit 635bd26

Browse files
feat(api): manual updates
1 parent 25126eb commit 635bd26

File tree

5 files changed

+66
-126
lines changed

5 files changed

+66
-126
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 5
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cas-parser%2Fcas-parser-b7fdba3d3f97c7debc22c7ca30b828bce81bcd64648df8c94029b27a3321ebb9.yml
33
openapi_spec_hash: 03f1315f1d32ada42445ca920f047dff
4-
config_hash: 1de8a243a3962065e289ca915dfc6127
4+
config_hash: d9c1f7b95d5659724df3e026c4fab291

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ from cas_parser import CasParser
3333

3434
client = CasParser(
3535
api_key=os.environ.get("CAS_PARSER_API_KEY"), # This is the default and can be omitted
36-
# defaults to "production".
37-
environment="local",
3836
)
3937

40-
unified_response = client.cas_parser.cams_kfintech()
38+
unified_response = client.cas_parser.smart_parse(
39+
password="ABCDF",
40+
pdf_url="https://your-cas-pdf-url-here.com",
41+
)
4142
print(unified_response.demat_accounts)
4243
```
4344

@@ -57,13 +58,14 @@ from cas_parser import AsyncCasParser
5758

5859
client = AsyncCasParser(
5960
api_key=os.environ.get("CAS_PARSER_API_KEY"), # This is the default and can be omitted
60-
# defaults to "production".
61-
environment="local",
6261
)
6362

6463

6564
async def main() -> None:
66-
unified_response = await client.cas_parser.cams_kfintech()
65+
unified_response = await client.cas_parser.smart_parse(
66+
password="ABCDF",
67+
pdf_url="https://your-cas-pdf-url-here.com",
68+
)
6769
print(unified_response.demat_accounts)
6870

6971

@@ -96,7 +98,10 @@ async def main() -> None:
9698
api_key="My API Key",
9799
http_client=DefaultAioHttpClient(),
98100
) as client:
99-
unified_response = await client.cas_parser.cams_kfintech()
101+
unified_response = await client.cas_parser.smart_parse(
102+
password="ABCDF",
103+
pdf_url="https://your-cas-pdf-url-here.com",
104+
)
100105
print(unified_response.demat_accounts)
101106

102107

@@ -128,7 +133,10 @@ from cas_parser import CasParser
128133
client = CasParser()
129134

130135
try:
131-
client.cas_parser.cams_kfintech()
136+
client.cas_parser.smart_parse(
137+
password="ABCDF",
138+
pdf_url="https://you-cas-pdf-url-here.com",
139+
)
132140
except cas_parser.APIConnectionError as e:
133141
print("The server could not be reached")
134142
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -171,7 +179,10 @@ client = CasParser(
171179
)
172180

173181
# Or, configure per-request:
174-
client.with_options(max_retries=5).cas_parser.cams_kfintech()
182+
client.with_options(max_retries=5).cas_parser.smart_parse(
183+
password="ABCDF",
184+
pdf_url="https://you-cas-pdf-url-here.com",
185+
)
175186
```
176187

177188
### Timeouts
@@ -194,7 +205,10 @@ client = CasParser(
194205
)
195206

196207
# Override per-request:
197-
client.with_options(timeout=5.0).cas_parser.cams_kfintech()
208+
client.with_options(timeout=5.0).cas_parser.smart_parse(
209+
password="ABCDF",
210+
pdf_url="https://you-cas-pdf-url-here.com",
211+
)
198212
```
199213

200214
On timeout, an `APITimeoutError` is thrown.
@@ -235,10 +249,13 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
235249
from cas_parser import CasParser
236250

237251
client = CasParser()
238-
response = client.cas_parser.with_raw_response.cams_kfintech()
252+
response = client.cas_parser.with_raw_response.smart_parse(
253+
password="ABCDF",
254+
pdf_url="https://you-cas-pdf-url-here.com",
255+
)
239256
print(response.headers.get('X-My-Header'))
240257

241-
cas_parser = response.parse() # get the object that `cas_parser.cams_kfintech()` would have returned
258+
cas_parser = response.parse() # get the object that `cas_parser.smart_parse()` would have returned
242259
print(cas_parser.demat_accounts)
243260
```
244261

@@ -253,7 +270,10 @@ The above interface eagerly reads the full response body when you make the reque
253270
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
254271

255272
```python
256-
with client.cas_parser.with_streaming_response.cams_kfintech() as response:
273+
with client.cas_parser.with_streaming_response.smart_parse(
274+
password="ABCDF",
275+
pdf_url="https://you-cas-pdf-url-here.com",
276+
) as response:
257277
print(response.headers.get("X-My-Header"))
258278

259279
for line in response.iter_lines():

src/cas_parser/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
77
from ._utils import file_from_path
88
from ._client import (
9-
ENVIRONMENTS,
109
Client,
1110
Stream,
1211
Timeout,
@@ -72,7 +71,6 @@
7271
"AsyncStream",
7372
"CasParser",
7473
"AsyncCasParser",
75-
"ENVIRONMENTS",
7674
"file_from_path",
7775
"BaseModel",
7876
"DEFAULT_TIMEOUT",

src/cas_parser/_client.py

Lines changed: 12 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Dict, Union, Mapping, cast
7-
from typing_extensions import Self, Literal, override
6+
from typing import Any, Union, Mapping
7+
from typing_extensions import Self, override
88

99
import httpx
1010

@@ -31,7 +31,6 @@
3131
)
3232

3333
__all__ = [
34-
"ENVIRONMENTS",
3534
"Timeout",
3635
"Transport",
3736
"ProxiesTypes",
@@ -42,11 +41,6 @@
4241
"AsyncClient",
4342
]
4443

45-
ENVIRONMENTS: Dict[str, str] = {
46-
"production": "https://portfolio-parser.api.casparser.in",
47-
"local": "http://localhost:5000",
48-
}
49-
5044

5145
class CasParser(SyncAPIClient):
5246
cas_parser: cas_parser.CasParserResource
@@ -57,14 +51,11 @@ class CasParser(SyncAPIClient):
5751
# client options
5852
api_key: str
5953

60-
_environment: Literal["production", "local"] | NotGiven
61-
6254
def __init__(
6355
self,
6456
*,
6557
api_key: str | None = None,
66-
environment: Literal["production", "local"] | NotGiven = NOT_GIVEN,
67-
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
58+
base_url: str | httpx.URL | None = None,
6859
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
6960
max_retries: int = DEFAULT_MAX_RETRIES,
7061
default_headers: Mapping[str, str] | None = None,
@@ -95,31 +86,10 @@ def __init__(
9586
)
9687
self.api_key = api_key
9788

98-
self._environment = environment
99-
100-
base_url_env = os.environ.get("CAS_PARSER_BASE_URL")
101-
if is_given(base_url) and base_url is not None:
102-
# cast required because mypy doesn't understand the type narrowing
103-
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
104-
elif is_given(environment):
105-
if base_url_env and base_url is not None:
106-
raise ValueError(
107-
"Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
108-
)
109-
110-
try:
111-
base_url = ENVIRONMENTS[environment]
112-
except KeyError as exc:
113-
raise ValueError(f"Unknown environment: {environment}") from exc
114-
elif base_url_env is not None:
115-
base_url = base_url_env
116-
else:
117-
self._environment = environment = "production"
118-
119-
try:
120-
base_url = ENVIRONMENTS[environment]
121-
except KeyError as exc:
122-
raise ValueError(f"Unknown environment: {environment}") from exc
89+
if base_url is None:
90+
base_url = os.environ.get("CAS_PARSER_BASE_URL")
91+
if base_url is None:
92+
base_url = f"https://portfolio-parser.api.casparser.in"
12393

12494
super().__init__(
12595
version=__version__,
@@ -161,7 +131,6 @@ def copy(
161131
self,
162132
*,
163133
api_key: str | None = None,
164-
environment: Literal["production", "local"] | None = None,
165134
base_url: str | httpx.URL | None = None,
166135
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
167136
http_client: httpx.Client | None = None,
@@ -197,7 +166,6 @@ def copy(
197166
return self.__class__(
198167
api_key=api_key or self.api_key,
199168
base_url=base_url or self.base_url,
200-
environment=environment or self._environment,
201169
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
202170
http_client=http_client,
203171
max_retries=max_retries if is_given(max_retries) else self.max_retries,
@@ -253,14 +221,11 @@ class AsyncCasParser(AsyncAPIClient):
253221
# client options
254222
api_key: str
255223

256-
_environment: Literal["production", "local"] | NotGiven
257-
258224
def __init__(
259225
self,
260226
*,
261227
api_key: str | None = None,
262-
environment: Literal["production", "local"] | NotGiven = NOT_GIVEN,
263-
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
228+
base_url: str | httpx.URL | None = None,
264229
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
265230
max_retries: int = DEFAULT_MAX_RETRIES,
266231
default_headers: Mapping[str, str] | None = None,
@@ -291,31 +256,10 @@ def __init__(
291256
)
292257
self.api_key = api_key
293258

294-
self._environment = environment
295-
296-
base_url_env = os.environ.get("CAS_PARSER_BASE_URL")
297-
if is_given(base_url) and base_url is not None:
298-
# cast required because mypy doesn't understand the type narrowing
299-
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
300-
elif is_given(environment):
301-
if base_url_env and base_url is not None:
302-
raise ValueError(
303-
"Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
304-
)
305-
306-
try:
307-
base_url = ENVIRONMENTS[environment]
308-
except KeyError as exc:
309-
raise ValueError(f"Unknown environment: {environment}") from exc
310-
elif base_url_env is not None:
311-
base_url = base_url_env
312-
else:
313-
self._environment = environment = "production"
314-
315-
try:
316-
base_url = ENVIRONMENTS[environment]
317-
except KeyError as exc:
318-
raise ValueError(f"Unknown environment: {environment}") from exc
259+
if base_url is None:
260+
base_url = os.environ.get("CAS_PARSER_BASE_URL")
261+
if base_url is None:
262+
base_url = f"https://portfolio-parser.api.casparser.in"
319263

320264
super().__init__(
321265
version=__version__,
@@ -357,7 +301,6 @@ def copy(
357301
self,
358302
*,
359303
api_key: str | None = None,
360-
environment: Literal["production", "local"] | None = None,
361304
base_url: str | httpx.URL | None = None,
362305
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
363306
http_client: httpx.AsyncClient | None = None,
@@ -393,7 +336,6 @@ def copy(
393336
return self.__class__(
394337
api_key=api_key or self.api_key,
395338
base_url=base_url or self.base_url,
396-
environment=environment or self._environment,
397339
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
398340
http_client=http_client,
399341
max_retries=max_retries if is_given(max_retries) else self.max_retries,

0 commit comments

Comments
 (0)