sc4net package
Module contents
- sc4net.delete(url, headers=None, encoding='utf-8', decode=True, **kwargs)[source]
Not implemented. Intended for sending a DELETE request.
- Parameters:
url – str The URL to send the request to.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
decode – bool, default True Whether to decode the response.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
None Always raises NotImplementedError.
- Examples:
delete('https://example.com/api')
- sc4net.delete_json(url, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)[source]
Not implemented. Intended for sending a DELETE request with JSON response.
- Parameters:
url – str The URL to send the request to.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
json_kwargs – dict or None, optional Extra arguments for json.loads.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
None Always raises NotImplementedError.
- Examples:
delete_json('https://example.com/api')
- sc4net.get(url, headers=None, encoding: str | None = 'utf-8', decode=True, **kwargs)[source]
Download content from an HTTP(S) or FTP URL.
- Parameters:
url – str The URL to fetch (http, https, or ftp).
headers – dict or None, optional Additional headers to send with the request.
encoding – str or None, default “utf-8” Encoding to decode the response. If None, returns bytes.
decode – bool, default True Whether to decode the response using the specified encoding.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
str: Decoded content if decode is True and encoding is not None.
bytes: Raw content otherwise.
- Examples:
from sc4net import get text = get('https://example.com/data.txt') print(text) binary = get('ftp://ftp.example.com/file.zip', decode=False)
- sc4net.get_json(url, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)[source]
Download and decode JSON content from an HTTP(S) or FTP URL.
- Parameters:
url – str The URL to fetch.
headers – dict or None, optional Additional headers to send with the request.
encoding – str, default “utf-8” Encoding to decode the response.
json_kwargs – dict or None, optional Extra arguments for json.loads.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
dict or list: Parsed JSON content.
- Examples:
from sc4net import get_json data = get_json('https://example.com/data.json') print(data)
- sc4net.get_zip(url, headers=None, **kwargs)[source]
Downloads a ZIP file from a URL and returns a ZipFile object.
- Parameters:
url – str The URL to fetch.
headers – dict or None, optional Additional headers to send with the request.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
ZipFile: Opened ZipFile object.
- Examples:
zf = get_zip('https://example.com/archive.zip') print(zf.namelist())
- sc4net.get_zip_content(url, headers=None, file_id=0, encoding='utf-8', **kwargs)[source]
Download a ZIP file from a URL and extract the content of a file inside it.
- Parameters:
url – str The URL to fetch.
headers – dict or None, optional Additional headers to send with the request.
file_id – int or str, default 0 Index or name of the file inside the ZIP to extract.
encoding – str or None, default “utf-8” Encoding to decode the extracted file. If None, returns bytes.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
str: Decoded file content if encoding is not None.
bytes: Raw file content otherwise.
- Examples:
from sc4net import get_zip_content text = get_zip_content('https://example.com/archive.zip', file_id=0) print(text)
- sc4net.get_zip_csv_content(url, headers=None, file_id=0, encoding='utf-8', unzip_kwargs=None, **kwargs)[source]
Downloads a ZIP file from a URL, extracts a CSV, and parses it as a list of dicts.
- Parameters:
url – str The URL to fetch.
headers – dict or None, optional Additional headers to send with the request.
file_id – int or str, default 0 Index or name of the file inside the ZIP to extract.
encoding – str, default “utf-8” Encoding to decode the extracted file.
unzip_kwargs – dict or None, optional Additional arguments for csv.DictReader.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
list of dict: Parsed CSV rows.
- Examples:
rows = get_zip_csv_content('https://example.com/archive.zip', file_id=0)
- sc4net.post(url, data=None, json_data=None, headers=None, encoding='utf-8', decode=True, **kwargs)[source]
Send a POST request to an HTTP(S) URL.
- Parameters:
url – str The URL to send the request to.
data – dict, str, bytes or None, optional Data to send in the body (form or raw).
json_data – dict or None, optional JSON data to send in the body.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
decode – bool, default True Whether to decode the response.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
str: Decoded response if decode is True and encoding is not None.
bytes: Raw response otherwise.
- Examples:
from sc4net import post response = post('https://example.com/api', data={'key': 'value'}) print(response)
- sc4net.post_json(url, data=None, json_data=None, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)[source]
Sends a POST request and decodes the JSON response.
- Parameters:
url – str The URL to send the request to.
data – dict, str, bytes or None, optional Data to send in the body (form or raw).
json_data – dict or None, optional JSON data to send in the body.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
json_kwargs – dict or None, optional Extra arguments for json.loads.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
dict or list: Parsed JSON content.
- Examples:
resp = post_json('https://example.com/api', json_data={'a': 1})
- sc4net.put(url, data=None, json_data=None, headers=None, encoding='utf-8', **kwargs)[source]
Not implemented. Intended for sending a PUT request.
- Parameters:
url – str The URL to send the request to.
data – dict, str, bytes or None, optional Data to send in the body (form or raw).
json_data – dict or None, optional JSON data to send in the body.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
None Always raises NotImplementedError.
- Examples:
put('https://example.com/api', data={'a': 1})
- sc4net.put_json(url, data=None, json_data=None, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)[source]
Not implemented. Intended for sending a PUT request with JSON response.
- Parameters:
url – str The URL to send the request to.
data – dict, str, bytes or None, optional Data to send in the body (form or raw).
json_data – dict or None, optional JSON data to send in the body.
headers – dict or None, optional Additional headers to send.
encoding – str, default “utf-8” Encoding for the request and response.
json_kwargs – dict or None, optional Extra arguments for json.loads.
kwargs – dict Additional arguments, e.g., timeout.
- Returns:
None Always raises NotImplementedError.
- Examples:
put_json('https://example.com/api', json_data={'a': 1})