Metadata-Version: 2.1
Name: cookiecache
Version: 1.1
Summary: Simplify getting and storing cookies from the browser to use in Python
Home-page: https://github.com/pathtofile/cookiecache
Author: PatH
Author-email: pypi_cookiecache@tofile.dev
License: MIT
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: browser-cookie3

# CookieCache
Simplify getting and using cookies from the browser to use in Python.

**NOTE**: All the logic to interface with the browsers is done by the
[Browser Cookie 3](https://github.com/borisbabic/browser_cookie3) library.

This code wraps that BrowserCookie3 in a CLI and library that caches
the selected cookies as JSON to disk, so they can be transferred to
other machines, or be used again without having to interactivly
re-enter MacOS user credentials.

# Install
```bash
pip install cookiecache
```

# Usage
The idea is you run cookiecache once (either as a cli tool or as a library), and
then cache the cookies to JSON on disk. Then the next time you run the same thing, cookiecache
will look in the JSON file first, and only get fresh cookies from the browser if they have expired.

## CLI
Examples:
```bash
# Get github session cookies and save to disk
cookiecache --domain "github.com" --cookie "_gh_sess" --filename "cookies.json"

# Get all github cookies in Netscape/Mozilla format to use with curl, et.c:
cookiecache --domain "github.com" --filename "cookies.txt" --curl

# All options:
cookiecache --help
```

## Library
To use cookiecache as a library call `load_cookies()` with arguments similar to
the cli:
```python
import cookiecache

# Get github session cookies and save to disk
# After the first run this will load the cookies
# from disk first, and only get them from the brower
# if they have expired
cookies = cookiecache.load_cookies(
    domain_name="github.com",
    cookie_name="_gh_sess",
    filename="cookies.json",
)

# Load all cookies from JSON file from another machine, ie.
# Don't attempt to refresh or get cookies from this machine
cookies = cookiecache.load_cookies(
    filename="cookies.json",
    check_expiry=False
)

# Get cookies only from Chrome, and don't read or save to disk
cookies = cookiecache.load_cookies(
    domain_name="github.com",
    browser="chrome",
)

# Convert cookies from cookiecache to a flat key-value
# pair to use with Requests
cookies = cookiecache.load_cookies(domain_name="github.com")
cookies_flat = cookiecache.flatten_cookies(cookies)
reqeusts.get("http://github.com", cookies=cookies_flat)
```


