Skip to content

Commit e82ddae

Browse files
authored
Use lowercased method name convention (#9)
* Use lowercased method name convention This renames the Article, PDF, and Summary methods to lowercase, matching standard Python naming conventions and avoiding any overlap with the model type names. We have aliases for the previous names for backwards compatibility. * Emit deprecation warnings
1 parent 92b7975 commit e82ddae

5 files changed

Lines changed: 117 additions & 68 deletions

File tree

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from instaparser import InstaparserClient
1717
client = InstaparserClient(api_key="your-api-key")
1818

1919
# Parse an article from a URL
20-
article = client.Article(url="https://example.com/article")
20+
article = client.article(url="https://example.com/article")
2121

2222
# Access article properties
2323
print(article.title)
@@ -46,34 +46,34 @@ from instaparser import InstaparserClient
4646
client = InstaparserClient(api_key="your-api-key")
4747

4848
# Parse from URL (HTML output)
49-
article = client.Article(url="https://example.com/article")
49+
article = client.article(url="https://example.com/article")
5050
print(article.html) # HTML content
5151
print(article.body) # Same as html when output='html'
5252

5353
# Parse from URL (text output)
54-
article = client.Article(url="https://example.com/article", output="text")
54+
article = client.article(url="https://example.com/article", output="text")
5555
print(article.text) # Plain text content
5656
print(article.body) # Same as text when output='text'
5757

5858
# Parse from URL (markdown output)
59-
article = client.Article(url="https://example.com/article", output="markdown")
59+
article = client.article(url="https://example.com/article", output="markdown")
6060
print(article.markdown) # Markdown content
6161
print(article.body) # Same as markdown when output='markdown'
6262

6363
# Parse from HTML content
6464
html_content = "<html><body><h1>Title</h1><p>Content</p></body></html>"
65-
article = client.Article(url="https://example.com/article", content=html_content)
65+
article = client.article(url="https://example.com/article", content=html_content)
6666

6767
# Disable cache
68-
article = client.Article(url="https://example.com/article", use_cache=False)
68+
article = client.article(url="https://example.com/article", use_cache=False)
6969
```
7070

7171
### Article Properties
7272

7373
The `Article` object provides access to all parsed metadata:
7474

7575
```python
76-
article = client.Article(url="https://example.com/article")
76+
article = client.article(url="https://example.com/article")
7777

7878
# Basic properties
7979
article.url # Canonical URL
@@ -103,7 +103,7 @@ Generate AI-powered summaries:
103103

104104
```python
105105
# Generate summary
106-
summary = client.Summary(url="https://example.com/article")
106+
summary = client.summary(url="https://example.com/article")
107107

108108
print(summary.overview) # Concise summary
109109
print(summary.key_sentences) # List of key sentences
@@ -112,7 +112,7 @@ print(summary.key_sentences) # List of key sentences
112112
def on_stream_line(line):
113113
print(f"Streaming: {line}")
114114

115-
summary = client.Summary(
115+
summary = client.summary(
116116
url="https://example.com/article",
117117
stream_callback=on_stream_line
118118
)
@@ -124,19 +124,19 @@ Parse PDFs from URLs or files. The PDF class inherits from Article, so it has al
124124

125125
```python
126126
# Parse PDF from URL
127-
pdf = client.PDF(url="https://example.com/document.pdf")
127+
pdf = client.pdf(url="https://example.com/document.pdf")
128128

129129
# Parse PDF from file
130130
with open('document.pdf', 'rb') as f:
131-
pdf = client.PDF(file=f)
131+
pdf = client.pdf(file=f)
132132

133133
# Parse PDF with text output
134-
pdf = client.PDF(url="https://example.com/document.pdf", output="text")
134+
pdf = client.pdf(url="https://example.com/document.pdf", output="text")
135135
print(pdf.text)
136136
print(pdf.body) # Same as text when output='text'
137137

138138
# Parse PDF with markdown output
139-
pdf = client.PDF(url="https://example.com/document.pdf", output="markdown")
139+
pdf = client.pdf(url="https://example.com/document.pdf", output="markdown")
140140
print(pdf.markdown)
141141
print(pdf.body) # Same as markdown when output='markdown'
142142

@@ -162,7 +162,7 @@ from instaparser import (
162162
client = InstaparserClient(api_key="your-api-key")
163163

164164
try:
165-
article = client.Article(url="https://example.com/article")
165+
article = client.article(url="https://example.com/article")
166166
except InstaparserAuthenticationError:
167167
print("Invalid API key")
168168
except InstaparserRateLimitError:
@@ -185,7 +185,7 @@ Initialize the client.
185185

186186
- `api_key`: Your Instaparser API key
187187

188-
#### `Article(url: str, content: Optional[str] = None, output: str = 'html', use_cache: bool = True) -> Article`
188+
#### `article(url: str, content: Optional[str] = None, output: str = 'html', use_cache: bool = True) -> Article`
189189

190190
Parse an article from a URL or HTML content.
191191

@@ -196,7 +196,7 @@ Parse an article from a URL or HTML content.
196196

197197
Returns: `Article` object
198198

199-
#### `Summary(url: str, content: Optional[str] = None, use_cache: bool = True, stream_callback: Optional[Callable[[str], None]] = None) -> Summary`
199+
#### `summary(url: str, content: Optional[str] = None, use_cache: bool = True, stream_callback: Optional[Callable[[str], None]] = None) -> Summary`
200200

201201
Generate a summary of an article.
202202

@@ -207,7 +207,7 @@ Generate a summary of an article.
207207

208208
Returns: `Summary` object with `key_sentences` and `overview` attributes
209209

210-
#### `PDF(url: Optional[str] = None, file: Optional[Union[BinaryIO, bytes]] = None, output: str = 'html', use_cache: bool = True) -> PDF`
210+
#### `pdf(url: Optional[str] = None, file: Optional[Union[BinaryIO, bytes]] = None, output: str = 'html', use_cache: bool = True) -> PDF`
211211

212212
Parse a PDF from a URL or file.
213213

example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_api_key(args: argparse.Namespace) -> str:
3030

3131
def cmd_article(client: InstaparserClient, args: argparse.Namespace) -> None:
3232
"""Call Article API and print result."""
33-
article = client.Article(
33+
article = client.article(
3434
url=args.url,
3535
output=args.output,
3636
use_cache=not args.no_cache,
@@ -53,7 +53,7 @@ def on_stream(line: str) -> None:
5353
if args.stream:
5454
print(f" {line}")
5555

56-
summary = client.Summary(
56+
summary = client.summary(
5757
url=args.url,
5858
use_cache=not args.no_cache,
5959
stream_callback=on_stream if args.stream else None,
@@ -68,7 +68,7 @@ def cmd_pdf(client: InstaparserClient, args: argparse.Namespace) -> None:
6868
"""Call PDF API and print result."""
6969
if args.file:
7070
with open(args.file, "rb") as f:
71-
pdf = client.PDF(
71+
pdf = client.pdf(
7272
file=f,
7373
url=args.url or None,
7474
output=args.output,
@@ -78,7 +78,7 @@ def cmd_pdf(client: InstaparserClient, args: argparse.Namespace) -> None:
7878
if not args.url:
7979
print("Error: --url or --file required for pdf.", file=sys.stderr)
8080
sys.exit(1)
81-
pdf = client.PDF(
81+
pdf = client.pdf(
8282
url=args.url,
8383
output=args.output,
8484
use_cache=not args.no_cache,

instaparser/client.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import json
66
import uuid
7+
import warnings
78
from collections.abc import Callable
89
from http.client import HTTPResponse
910
from typing import Any, BinaryIO, NoReturn
@@ -101,7 +102,7 @@ class InstaparserClient:
101102
102103
Example:
103104
>>> client = InstaparserClient(api_key="your-api-key")
104-
>>> article = client.Article(url="https://example.com/article")
105+
>>> article = client.article(url="https://example.com/article")
105106
>>> print(article.body)
106107
"""
107108

@@ -185,7 +186,7 @@ def _read_json(self, response: HTTPResponse) -> dict[str, Any]:
185186
pass
186187
return {"raw": body}
187188

188-
def Article(self, url: str, content: str | None = None, output: str = "html", use_cache: bool = True) -> Article:
189+
def article(self, url: str, content: str | None = None, output: str = "html", use_cache: bool = True) -> Article:
189190
"""
190191
Parse an article from a URL or HTML content.
191192
@@ -199,7 +200,7 @@ def Article(self, url: str, content: str | None = None, output: str = "html", us
199200
Article object with parsed content
200201
201202
Example:
202-
>>> article = client.Article(url="https://example.com/article")
203+
>>> article = client.article(url="https://example.com/article")
203204
>>> print(article.title)
204205
>>> print(article.body)
205206
"""
@@ -238,7 +239,7 @@ def Article(self, url: str, content: str | None = None, output: str = "html", us
238239
markdown=data.get("markdown"),
239240
)
240241

241-
def Summary(
242+
def summary(
242243
self,
243244
url: str,
244245
content: str | None = None,
@@ -259,14 +260,14 @@ def Summary(
259260
Summary object with key_sentences and overview attributes
260261
261262
Example:
262-
>>> summary = client.Summary(url="https://example.com/article")
263+
>>> summary = client.summary(url="https://example.com/article")
263264
>>> print(summary.overview)
264265
>>> print(summary.key_sentences)
265266
266267
>>> # With streaming callback
267268
>>> def on_line(line):
268269
... print(f"Received: {line}")
269-
>>> summary = client.Summary(url="https://example.com/article", stream_callback=on_line)
270+
>>> summary = client.summary(url="https://example.com/article", stream_callback=on_line)
270271
"""
271272
payload: dict[str, Any] = {
272273
"url": url,
@@ -305,7 +306,7 @@ def Summary(
305306
data = self._read_json(response)
306307
return Summary(key_sentences=data.get("key_sentences", []), overview=data.get("overview", ""))
307308

308-
def PDF(
309+
def pdf(
309310
self,
310311
url: str | None = None,
311312
file: BinaryIO | bytes | None = None,
@@ -326,11 +327,11 @@ def PDF(
326327
327328
Example:
328329
>>> # Parse PDF from URL
329-
>>> pdf = client.PDF(url="https://example.com/document.pdf")
330+
>>> pdf = client.pdf(url="https://example.com/document.pdf")
330331
331332
>>> # Parse PDF from file
332333
>>> with open('document.pdf', 'rb') as f:
333-
... pdf = client.PDF(file=f)
334+
... pdf = client.pdf(file=f)
334335
"""
335336
if output not in ("html", "text", "markdown"):
336337
raise InstaparserValidationError("output must be 'html', 'text', or 'markdown'")
@@ -381,3 +382,32 @@ def PDF(
381382
text=result.get("text"),
382383
markdown=result.get("markdown"),
383384
)
385+
386+
# Deprecated aliases for backwards compatibility:
387+
388+
def Article(self, *args: Any, **kwargs: Any) -> Article: # noqa: N802
389+
"""Deprecated: use client.article() instead."""
390+
warnings.warn(
391+
"client.Article() is deprecated, use client.article() instead",
392+
DeprecationWarning,
393+
stacklevel=2,
394+
)
395+
return self.article(*args, **kwargs)
396+
397+
def PDF(self, *args: Any, **kwargs: Any) -> PDF: # noqa: N802
398+
"""Deprecated: use client.pdf() instead."""
399+
warnings.warn(
400+
"client.PDF() is deprecated, use client.pdf() instead",
401+
DeprecationWarning,
402+
stacklevel=2,
403+
)
404+
return self.pdf(*args, **kwargs)
405+
406+
def Summary(self, *args: Any, **kwargs: Any) -> Summary: # noqa: N802
407+
"""Deprecated: use client.summary() instead."""
408+
warnings.warn(
409+
"client.Summary() is deprecated, use client.summary() instead",
410+
DeprecationWarning,
411+
stacklevel=2,
412+
)
413+
return self.summary(*args, **kwargs)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,3 @@ line-length = 120
7777

7878
[tool.ruff.lint]
7979
select = ["E", "F", "I", "N", "W", "UP"]
80-
ignore = ["N802"]

0 commit comments

Comments
 (0)