{"id":13802090,"url":"https://github.com/jczic/MicroWebCli","last_synced_at":"2025-05-13T12:32:22.811Z","repository":{"id":55732918,"uuid":"106231503","full_name":"jczic/MicroWebCli","owner":"jczic","description":"A micro HTTP Web client for MicroPython (used on Pycom modules \u0026 ESP32)","archived":false,"fork":false,"pushed_at":"2020-12-12T20:08:52.000Z","size":78,"stargazers_count":57,"open_issues_count":8,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T04:41:23.354Z","etag":null,"topics":["authentication","download","esp32","files","hc2","http","https","json","lopy","micropython","pycom","redirection","request","socks5","ssl","web-client","wipy"],"latest_commit_sha":null,"homepage":"https://microwebcli.hc2.fr","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jczic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-09T03:14:25.000Z","updated_at":"2025-03-27T16:07:25.000Z","dependencies_parsed_at":"2022-08-15T06:40:30.466Z","dependency_job_id":null,"html_url":"https://github.com/jczic/MicroWebCli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroWebCli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroWebCli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroWebCli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroWebCli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jczic","download_url":"https://codeload.github.com/jczic/MicroWebCli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942613,"owners_count":21988098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","download","esp32","files","hc2","http","https","json","lopy","micropython","pycom","redirection","request","socks5","ssl","web-client","wipy"],"created_at":"2024-08-04T00:01:35.561Z","updated_at":"2025-05-13T12:32:22.518Z","avatar_url":"https://github.com/jczic.png","language":"Python","readme":"## MicroWebCli is a micro HTTP Web client for MicroPython (used on ESP32 and [Pycom](http://www.pycom.io) modules)\n\n![HC²](hc2.png \"HC²\")\n\nVery easy to integrate and very light with only one file :\n- `\"microWebCli.py\"`\n\nSimple but effective :\n- Use it to requesting fastly HTTP endpoints\n- Supports URL parts and modifiable query string parameters\n- Supports secured connections *SSL/TLS over HTTP* (https)\n- Supports SOCKS5 server (without authentication)\n- Supports authentications *HTTP Basic* and *Bearer Token*\n- Supports large request and response datas\n- Supports form-urlencoded datas on request\n- Supports json objects on request and response\n- Coulds save to a file the response content of any request\n- Adds fast methods to directly GET, POST, JSON and downloads\n- Automatically bounces (fast methods) on HTTP(S) redirections (ressources moved)\n\n### Using *microWebCli* fast methods (statics, without classes) :\n\n| Name  | Function |\n| - | - |\n| Makes a GET request | `MicroWebCli.GETRequest(url, queryParams=None, auth=None, connTimeoutSec=None)` |\n| Makes a POST request | `MicroWebCli.POSTRequest(url, formData={}, auth=None, connTimeoutSec=None)` |\n| Makes a JSON GET/POST request | `MicroWebCli.JSONRequest(url, o=None, auth=None, connTimeoutSec=None)` |\n| Save response of a GET request to file | `MicroWebCli.FileRequest(url, filepath, progressCallback=None, auth=None, connTimeoutSec=None)` |\n\n**`Note` : All fast methods automatically bounces on HTTP(S) redirections**\n\n**`Warning` : Entire content of the response is allocated in memory with GETRequest, POSTRequest and JSONRequest**\n\n### Fast methods usage example :\n```python\nfrom microWebCli import MicroWebCli\n\ncontentBytes = MicroWebCli.GETRequest('http://my-web-site.io/test.html', { 'pet':'cat' })\nprint(contentBytes)\n\ncontentBytes = MicroWebCli.POSTRequest('http://my-web-site.io/post.php', { 'id':12345 })\nprint(contentBytes)\n\nauth   = MicroWebCli.AuthBasic('toto', 'blah123')\nresult = MicroWebCli.JSONRequest('http://my-web-site.io/my-api/user/12', auth=auth)\nprint('User name is %s %s' % (result.firstname, result.lastname))\n\ndef progressCallback(microWebCli, progressSize, totalSize) :\n  if totalSize :\n    print('Progress: %d bytes of %d downloaded...' % (progressSize, totalSize))\n  else :\n    print('Progress: %d bytes downloaded...' % progressSize)\nfilename    = '/flash/test.pdf'\ncontentType = MicroWebCli.FileRequest('http://my-web-site.io/test.pdf', filename, progressCallback)\nprint('File of content type \"%s\" was saved to \"%s\"' % (contentType, filename))\n```\n\n### Using *microWebCli* authentication classes :\n\n| Authentication  | Class constructor |\n| - | - |\n| Basic HTTP | `auth = MicroWebCli.AuthBasic(user, password)` |\n| Bearer Token | `auth = MicroWebCli.AuthToken(token)` |\n\n\n### Using *microWebCli* main class :\n\n| Name  | Function |\n| - | - |\n| Constructor | `wCli = MicroWebCli(url='', method='GET', auth=None, connTimeoutSec=None)` |\n| Opens HTTP request | `wCli.OpenRequest(data=None, contentType=None, contentLength=None)` |\n| Opens HTTP form-urlencoded request | `wCli.OpenRequestFormData(formData={})` |\n| Opens HTTP json object request | `wCli.OpenRequestJSONData(o=None)` |\n| Writes binary data to opened request | `wCli.RequestWriteData(data)` |\n| Gets response class for opened request | `wCli.GetResponse()` |\n| Checks if no request is opened | `wCli.IsClosed()` |\n| Closes an opened request | `wCli.Close()` |\n\n| Name  | Property |\n| - | - |\n| Gets or sets the connection timeout in secondes | `wCli.ConnTimeoutSec` |\n| Gets or sets the Web method verb | `wCli.Method` |\n| Gets or sets the complete Web URL | `wCli.URL` |\n| Gets or sets the Web proto (http/https) | `wCli.Proto` |\n| Gets or sets the Web host | `wCli.Host` |\n| Gets or sets the Web port number | `wCli.Port` |\n| Gets or sets the Web path part | `wCli.Path` |\n| Gets or sets the Web complete query string | `wCli.QueryString` |\n| Gets or sets the dict query parameters | `wCli.QueryParams` |\n| Gets or sets the dict headers | `wCli.Headers` |\n| Gets or sets the authentication class | `wCli.Auth` |\n| Gets or sets a SOCKS5 server (tuple of host and port) | `wCli.Socks5Addr` |\n\n### Using *microWebCli* response class :\n\n| Name  | Function |\n| - | - |\n| Gets the client microWebCli class | `resp.GetClient()` |\n| Gets the HTTP server address  | `resp.GetAddr()` |\n| Gets the HTTP server IP address | `resp.GetIPAddr()` |\n| Gets the HTTP server port number | `resp.GetPort()` |\n| Gets the HTTP server version | `resp.GetHTTPVersion()` |\n| Gets the response status code | `resp.GetStatusCode()` |\n| Gets the response status message | `resp.GetStatusMessage()` |\n| Checks if it is a success response | `resp.IsSuccess()` |\n| Checks if it is a location moved response | `resp.IsLocationMoved()` |\n| Gets the location moved URL | `resp.LocationMovedURL()` |\n| Gets the dict response headers | `resp.GetHeaders()` |\n| Gets the reponse content type | `resp.GetContentType()` |\n| Gets the response content length | `resp.GetContentLength()` |\n| Reads response content (part or total) | `resp.ReadContent(size=None)` |\n| Reads response content into buffer | `resp.ReadContentInto(buf, nbytes=None)()` |\n| Reads response content as json object | `resp.ReadContentAsJSON()` |\n| Writes response content to a file | `resp.WriteContentToFile(filepath, progressCallback=None)` |\n| Checks if response is closed | `resp.IsClosed()` |\n| Closes response | `resp.Close()` |\n\n\n### Example of GET (large response) :\n```python\nfrom microWebCli import MicroWebCli\n\nwCli = MicroWebCli('http://my-web-site.io/test.html')\nwCli.QueryParams['pet'] = 'cat'\nprint('GET %s' % wCli.URL)\nwCli.OpenRequest()\nbuf  = memoryview(bytearray(1024))\nresp = wCli.GetResponse()\nif resp.IsSuccess() :\n  while not resp.IsClosed() :\n    x = resp.ReadContentInto(buf)\n    if x \u003c len(buf) :\n      buf = buf[:x]\n    print(buf.decode())\n  print('GET success with \"%s\" content type' % resp.GetContentType())\nelse :\n  print('GET return %d code (%s)' % (resp.GetStatusCode(), resp.GetStatusMessage()))\n```\n\n### Example of PUT (large request) :\n```python\nfrom microWebCli import MicroWebCli\n\nauth = MicroWebCli.AuthToken('Dk23JHsI7NsMcY3C=')\nwCli = MicroWebCli('http://my-web-site.io/my-api/user/12', 'PUT', auth)\nprint('PUT %s' % wCli.URL)\nwCli.OpenRequest('application/octet-stream', fileSize)\nwhile True :\n  data = fileObject.read(1024)\n  if not data :\n    break\n  wCli.RequestWriteData(data)\nresp = wCli.GetResponse()\nif resp.IsSuccess() :\n  o = resp.ReadContentAsJSON()\n  print('PUT success')\nelse :\n  print('PUT return %d code (%s)' % (resp.GetStatusCode(), resp.GetStatusMessage()))\n```\n\n### Example of saving response to a file :\n```python\nfrom microWebCli import MicroWebCli\n\ndef progressCallback(microWebCli, progressSize, totalSize) :\n  if totalSize :\n    print('Progress: %d bytes of %d downloaded...' % (progressSize, totalSize))\n  else :\n    print('Progress: %d bytes downloaded...' % progressSize)\n\nfilename = '/flash/test.pdf'\nwCli = MicroWebCli('http://my-web-site.io/test.pdf')\nprint('GET file %s' % wCli.URL)\nwCli.OpenRequest()\nresp = wCli.GetResponse()\ncontentType = resp.WriteContentToFile(filename, progressCallback)\nprint('File of content type \"%s\" was saved to \"%s\"' % (contentType, filename))\n```\n\n\n### By JC`zic for [HC²](https://www.hc2.fr) ;')\n\n*Keep it simple, stupid* :+1:\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjczic%2FMicroWebCli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjczic%2FMicroWebCli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjczic%2FMicroWebCli/lists"}