Replace requests with urllib.request to reduce core dependencies - #1211
Merged
Conversation
|
Hello @Copilot, thank you for submitting a PR! We will respond as soon as possible. สวัสดี @Copilot ขอบคุณที่ส่ง PR เข้ามา เราจะตอบกลับให้เร็วที่สุดเท่าที่จะทำได้ |
Co-authored-by: bact <128572+bact@users.noreply.github.com>
…dling Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Reduce dependencies in PyThaiNLP package
Replace requests with urllib.request to reduce core dependencies
Jan 16, 2026
bact
reviewed
Jan 16, 2026
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Member
|
@copilot considering our use case, what is the best user-agent string? |
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Contributor
Author
For this use case (a Python library downloading corpus data from its own server), the best User-Agent identifies the actual client rather than masquerading as a browser. Updated in commit 9507e0d to use: This approach provides:
|
Removed duplicate entry for KeyError fix and updated the requests library replacement note.
|
wannaphong
approved these changes
Jan 17, 2026
bact
approved these changes
Jan 17, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What does this changes
Replaces the
requestslibrary with Python's standard libraryurllib.requestfor HTTP operations, reducing core dependencies from 2 to 1 (onlytzdatafor Windows remains).What was wrong
PyThaiNLP had
requests>=2.31as a core dependency solely for corpus download functionality (get_corpus_db()and_download()inpythainlp/corpus/core.py). This contributed to:How this fixes it
pythainlp/corpus/core.py: Replacedrequests.get()withurllib.request.urlopen()_ResponseWrapperclass for API compatibility with existing.json()method callsresponse.read(CHUNK_SIZE)requests.exceptions.*tourllib.error.*PyThaiNLP/5.2.0 (Python/3.12; linux))_USER_AGENTmodule-level constant used consistently across HTTP requestspyproject.toml: Removedrequests>=2.31from core dependenciesCHANGELOG.md: Documented the changeNo breaking changes—API surface remains identical.
Your checklist for this pull request
Original prompt