Skip to content

A barebones requests + requests-unixsocket clone implemented using only Python 2 and 3 standard libraries

License

Notifications You must be signed in to change notification settings

clayshieh/requests_stdlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Requests Standard Libary

A dependency free drop-in replacement for requests and requests-unixsocket for the common functions implemented using only Python 2 and 3 standard libraries.

Should I use this?

  • I have a project where I use requests because that's what everyone on stackoverflow tells me to do but I really only use simple GET/POST/PUT/DELETE functions.

  • I want to communicate with my Docker daemon but I think it's ridiculous that I have to install requests AND requests-unixsocket just to send HTTP requests to a unix socket file.

  • I have a project where the only dependency is requests and/or requests-unixsocket and I don't want to have to require users to install those just to use my project.

Well, if you find yourself thinking any of these when writing a project using request and/or requests-unixsocket then you should consider using this!

Prerequisites

None, that's the point.

Getting Started

Just drop requests.py into your project directory!

Usage

Features and usage are the same as requests quickstart for the following:

  • Make a Request link
  • Passing Parameters In URLs link
  • Response Content (except the encoding bit) link
  • JSON Response Content link
  • Custom Headers link
  • More complicated POST requests link
  • Response Status Codes (only the r.status_code bit) link
  • Response Headers link
  • Redirection and History (except the history bit) link

Unix socket usage is the same as requests-unixsocket documentation in regards to the scheme.

For example to send an HTTP request to /var/run/docker.sock you would use:

r = requests.get("http+unix://%2Fvar%2Frun%2Fdocker.sock/info")

TODO

I only implemented a subset of the features in requests which I found myself most commonly using. If there is interest for more of requests features I will implement them or feel free to make a PR if you want to add it yourself!

  • Binary Response Content link
  • Raw Response Content link
  • POST a Multipart-Encoded File link
  • Cookies link
  • Timeouts link

Acknowledgements

Referenced https://github.com/docker/docker-py/blob/master/docker/transport/unixconn.py for Docker's socket HTTPConnection code.

Contributing

Pull requests and contributions are welcomed!

Support

For any questions or concerns, please create an issue or contact me.

About

A barebones requests + requests-unixsocket clone implemented using only Python 2 and 3 standard libraries

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages