Improvement for the `urllib.request.urlopen` function.
Project description
urlopen2
Description
Improvement for the urllib.request.urlopen
function.
Install
pip install urlopen2
Using
Synchronous
from urlopen2 import URLFile
url = "https://example.com/file.bin"
with URLFile.open(url) as urlfile:
urlfile.read(128)
# In this case, 128 bytes of the file will be loaded.
urlfile.seek(0)
# Move the caret to the beginning of the file
data = urlfile.read(128)
# Since we are taking the same 128 bytes that have already been loaded, they will be received from the buffer.
print(data)
Asynchronous
import asyncio
import aiofiles
from urlopen2 import AsyncURLFile
url = "https://example.com/file.bin"
async def main():
async with aiofiles.open(*AsyncURLFile.gbuf()) as abuffer:
async with AsyncURLFile.open(url, abuffer) as aurlfile:
await aurlfile.read(128)
# In this case, 128 bytes of the file will be loaded.
await aurlfile.seek(0)
# Move the caret to the beginning of the file
data = await aurlfile.read(128)
# Since we are taking the same 128 bytes that have already been loaded, they will be received from the buffer.
print(data)
if __name__ == "__main__":
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
urlopen2-1.4.0.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file urlopen2-1.4.0.tar.gz
.
File metadata
- Download URL: urlopen2-1.4.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd3caad48a2383adecfb67fd3f510f32ac48b9d9d2d4b249b6e64aa32b460d89 |
|
MD5 | 161f90368e5347a01b6789a649ca8995 |
|
BLAKE2b-256 | df38688dd2bd952bfeabd386532268a5d5f8705bd748e77ffbf750fafbc4b6b9 |
File details
Details for the file urlopen2-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: urlopen2-1.4.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad46485fb4e3146db16571736b1e60ea21e6fa1ebbf98500df95621097d47cc9 |
|
MD5 | fdcf574051fb559ed0daedee94992159 |
|
BLAKE2b-256 | 5b0dbf492d7ca2cb97413b0b77037d721572e75a02b1f28f6da9586a635c9be2 |