Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ozansz/fastrequest
A Python C extension module for fast HTTP requests with SSL/TLS support
https://github.com/ozansz/fastrequest
c extension extensions http libcurl python python-c-api python-c-extension python3 requests socket socket-programming unix-socket winsock winsock2
Last synced: about 23 hours ago
JSON representation
A Python C extension module for fast HTTP requests with SSL/TLS support
- Host: GitHub
- URL: https://github.com/ozansz/fastrequest
- Owner: ozansz
- License: gpl-3.0
- Created: 2018-09-01T16:08:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-19T14:28:18.000Z (over 4 years ago)
- Last Synced: 2024-09-20T02:01:48.941Z (6 days ago)
- Topics: c, extension, extensions, http, libcurl, python, python-c-api, python-c-extension, python3, requests, socket, socket-programming, unix-socket, winsock, winsock2
- Language: C
- Size: 72.3 KB
- Stars: 8
- Watchers: 0
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastrequest
![GitHub](https://img.shields.io/github/license/ozansz/fastrequest)
![PyPI](https://img.shields.io/pypi/v/fastrequest)
![Requires.io](https://img.shields.io/requires/github/ozansz/fastrequest)
![PyPI - Implementation](https://img.shields.io/pypi/implementation/fastrequest)
![GitHub issues](https://img.shields.io/github/issues/ozansz/fastrequest)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ozansz/fastrequest)A Python C extension module for fast HTTP requests with SSL/TLS support
## Installation
To build and install the extension, you just need to run the `install.sh` script.
The script then installs required packages, builds the extension using `setuptools`
and then installs it using `pip`.```shell
chmod +x install.sh
./install.sh
```## Example Usage
Just import `fastrequest` module. It's usage is as easy as ABC!```python
import fastrequest.httpres = fastrequest.http.get("https://www.google.com")
res.save_to("index.html")
```Also, JSON (`application/json`) responses can be handled easily too.
```python
import json
import fastrequest.httpres = fastrequest.http.get("https://jsonplaceholder.typicode.com/comments?postId=1")
with open("data.json", "w") as fp:
json.dump(fp, res.json())
```## Module Reference
### HTTPResponse
HTTPResponse is the generic HTTP/HTTPS response object returned from the GET/POST functions.
Pythonic definition of HTTPResponse is as follows,
```Python
class HTTPResponse(object):
def __init__(self, data, size, url=""):
self.data = data
self.size = size
self.url = urldef text(self):
return self.data.decode()def json(self):
return json.loads(self.text())
```### http.get
`http.get(url: str[, headers:dict]) -> HTTPResponse`
HTTP/GET request function using `libcurl` as backend.
## API Reference
### HTTPResponse
HTTPResponse is the generic HTTP/HTTPS response object returned from the GET/POST functions.
The data structure of HTTPResponse object is as follows,
```C
typedef struct {
PyObject_HEAD
PyObject *response_size;
PyObject *response_data;
PyObject *request_url;
} HTTPResponseObject;
```Where
* `response_size` is byte-size of the response body (PyLong)
* `response_body` is the response body (PyBytes)
* `request_url` is the requested URI (PyUnicode)### StringBuffer
StringBuffer is the generic 'string' object implementation to be used in Fast Request API functions.
The data structure of StringBuffer object is as follows,
```C
typedef struct {
char *buf;
int_fast64_t index;
int_fast64_t size;
} StringBuffer;
```### FastRequestAPI_LibcurlHttpGet
`StringBuffer *FastRequestAPI_LibcurlHttpGet(char *url, PyObject *headers)`
Send HTTP/GET request to machine with the `url` specified with optional custom `headers`. This function uses `libcurl` as the backend.