Skip to main content

RequestsLoginSession

PyPI PyPI - Status PyPI - Downloads Code Climate maintainability Code Climate technical debt Pylint score Code Climate coverage Tests status GitHub last commit License PRs Welcome

requestsloginsession is a simple wrapper for requests.Session() that saves the data locally via pickle to allow session information to be recalled on subsequent script runs without needing to relogin. All the attributes from requests are available.

Install

From PyPi:

pip install requestsloginsession

Or use the latest commit:

git clone https://github.com/damonjavert/requestsloginsession.git
cd requestsloginsession
python setup.py install

Features

  • Saves cookie data to a local file via pickle and uses it to send cookie data in subsequent requests.
  • Cookie data saved has an expiry time - max_session_time_seconds, after which requestsloginsession will not send it, or you can force it not to be used with force_login.
  • Login success can be tested with a specific URL - login_test_url and string - login_test_string to be found on the page.
  • A proxy can be used.
  • Customisable user_agent string.

Example usage

>>> from requestsloginsession import RequestsLoginSession
>>> login_url = "http://httpbingo.org/"
>>> login_data = { 'username' : 'example', 'password' : 'example' }
>>> mysession = RequestsLoginSession(login_url, login_data)
>>> r = mysession.retrieve_content("http://httpbingo.org/cookies/set?k1=v1234&k2=v5678")
>>>
 $ file httpbingo.org_session.dat
httpbingo.org_session.dat: data
 $ # We have now exited python, when we start a new interpreter we can request httpbingo
 $ # to show our cookies and the `k1=v1234&k2=v5678` data will now be shown:
 $ python3

>>> from requestsloginsession import RequestsLoginSession
>>> login_url = "http://httpbingo.org/"
>>> login_data = { 'username' : 'example', 'password' : 'example' }
>>> mysession = RequestsLoginSession(login_url, login_data)
>>> r = mysession.retrieve_content("http://httpbingo.org/cookies")
>>> r.json()
{'k1': 'v1234', 'k2': 'v5678'}
>>> r.status_code
200
>>> r.text
'{\n  "k1": "v1234",\n  "k2": "v5678"\n}\n'

FAQ

Why not just use requests.Session() directly?

Of course you can do, but this module makes life easier by handling the cookie data for you and allowing the cookie data to survive multiple runs of your script, so you do not need to relogin each time.

I have an API key for the site I am requesting, do I still need to use this?

No, you probably do not. This module is designed to access sites where you need to authenticate before you can access it. Any modern API does not need this and you send an API key in each request. - If you have an API key you can just use requests directly.

Metadata

Release files for requestsloginsession 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for requestsloginsession 0.7.1
File Size Uploaded Provenance Actions
requestsloginsession-0.7.1.tar.gz 18.5 kB Without provenance Details for requestsloginsession-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for requestsloginsession 0.7.1
File Interpreter ABI Platform Actions
requestsloginsession-0.7.1-py3-none-any.whl Python 3 none any Details for requestsloginsession-0.7.1-py3-none-any.whl

Total release size: 36.8 kB

Release files / requestsloginsession-0.7.1.tar.gz

Download URL requestsloginsession-0.7.1.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b228d2828e7e91dc5aaa7adcd13d9c01968eba90deb27305e3084c2fce938738
BLAKE2b-256 checksum
How to use checksums
7f59717b66afca5b4f1d053abd87b068c60c5373326dc83ea53ee1c7de823f80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / requestsloginsession-0.7.1-py3-none-any.whl

Download URL requestsloginsession-0.7.1-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67d9e243c2b356fd408aded9345e8befa1383841c0fed566b2f87c537db59ce1
BLAKE2b-256 checksum
How to use checksums
cd6e3cb3e47b41c583db9ba5cf5329997efd5911aa0106002bdbb03efa08c69a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for requestsloginsession 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page