=============
Python Tokens
=============
.. image:: https://travis-ci.org/zalando-stups/python-tokens.svg?branch=master
:target: https://travis-ci.org/zalando-stups/python-tokens
:alt: Build Status
.. image:: https://coveralls.io/repos/zalando-stups/python-tokens/badge.svg
:target: https://coveralls.io/r/zalando-stups/python-tokens
:alt: Code Coverage
.. image:: https://img.shields.io/pypi/dw/stups-tokens.svg
:target: https://pypi.python.org/pypi/stups-tokens/
:alt: PyPI Downloads
.. image:: https://img.shields.io/pypi/v/stups-tokens.svg
:target: https://pypi.python.org/pypi/stups-tokens/
:alt: Latest PyPI version
.. image:: https://img.shields.io/pypi/l/stups-tokens.svg
:target: https://pypi.python.org/pypi/stups-tokens/
:alt: License
A Python library that keeps OAuth 2.0 service access tokens in memory for your usage.
Installation
============
.. code-block:: bash
$ sudo pip3 install --upgrade stups-tokens
Usage
=====
.. code-block:: python
import requests
import time
import tokens
# will use OAUTH2_ACCESS_TOKEN_URL environment variable by default
# will try to read application credentials from CREDENTIALS_DIR
tokens.configure(url='https://example.com/access_tokens')
tokens.manage('example', ['read', 'write'])
tokens.start()
tok = tokens.get('example')
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
time.sleep(3600) # make the token expire
tok = tokens.get('example') # will refresh the expired token
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
This library also allows reading tokens directly from a file. The token needs to be in a file name ``${CREDENTIALS_DIR}/${TOKEN_NAME}-secret``:
.. code-block:: python
import tokens
# the environment variable CREDENTIALS_DIR must be set correctly
tokens.configure(from_file_only=True)
tokens.manage('full-access')
tok = tokens.get('full-access')
requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})
Local testing
=============
The "tokens" library allows injecting fixed OAuth2 access tokens via the `OAUTH2_ACCESS_TOKENS` environment variable.
This allows testing applications using the library locally with personal OAuth2 tokens (e.g. generated by "zign"):
.. code-block:: bash
$ MY_TOKEN=$(zign token -n mytok)
$ export OAUTH2_ACCESS_TOKENS=mytok=$MY_TOKEN
$ ./myapp.py # start my local Python app using the tokens library
Releasing
=========
Uploading a new version to PyPI:
.. code-block:: bash
$ ./release.sh <NEW-VERSION>
Raw data
{
"_id": null,
"home_page": "https://github.com/zalando-stups/python-tokens",
"name": "stups-tokens",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Henning Jacobs",
"author_email": "henning.jacobs@zalando.de",
"download_url": "https://files.pythonhosted.org/packages/80/bb/d9b6991f59b7542ed6de9837e9160af066f6f47fb9515a412f0311315d2f/stups-tokens-1.1.19.tar.gz",
"platform": "UNKNOWN",
"description": "=============\nPython Tokens\n=============\n\n.. image:: https://travis-ci.org/zalando-stups/python-tokens.svg?branch=master\n :target: https://travis-ci.org/zalando-stups/python-tokens\n :alt: Build Status\n\n.. image:: https://coveralls.io/repos/zalando-stups/python-tokens/badge.svg\n :target: https://coveralls.io/r/zalando-stups/python-tokens\n :alt: Code Coverage\n\n.. image:: https://img.shields.io/pypi/dw/stups-tokens.svg\n :target: https://pypi.python.org/pypi/stups-tokens/\n :alt: PyPI Downloads\n\n.. image:: https://img.shields.io/pypi/v/stups-tokens.svg\n :target: https://pypi.python.org/pypi/stups-tokens/\n :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/l/stups-tokens.svg\n :target: https://pypi.python.org/pypi/stups-tokens/\n :alt: License\n\nA Python library that keeps OAuth 2.0 service access tokens in memory for your usage.\n\nInstallation\n============\n\n.. code-block:: bash\n\n $ sudo pip3 install --upgrade stups-tokens\n\nUsage\n=====\n\n.. code-block:: python\n\n import requests\n import time\n import tokens\n\n # will use OAUTH2_ACCESS_TOKEN_URL environment variable by default\n # will try to read application credentials from CREDENTIALS_DIR\n tokens.configure(url='https://example.com/access_tokens')\n tokens.manage('example', ['read', 'write'])\n tokens.start()\n\n tok = tokens.get('example')\n\n requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})\n\n time.sleep(3600) # make the token expire\n\n tok = tokens.get('example') # will refresh the expired token\n requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})\n\nThis library also allows reading tokens directly from a file. The token needs to be in a file name ``${CREDENTIALS_DIR}/${TOKEN_NAME}-secret``:\n\n.. code-block:: python\n\n import tokens\n\n # the environment variable CREDENTIALS_DIR must be set correctly\n tokens.configure(from_file_only=True)\n tokens.manage('full-access')\n tok = tokens.get('full-access')\n\n requests.get('https://example.org/', headers={'Authorization': 'Bearer {}'.format(tok)})\n\nLocal testing\n=============\n\nThe \"tokens\" library allows injecting fixed OAuth2 access tokens via the `OAUTH2_ACCESS_TOKENS` environment variable.\nThis allows testing applications using the library locally with personal OAuth2 tokens (e.g. generated by \"zign\"):\n\n.. code-block:: bash\n\n $ MY_TOKEN=$(zign token -n mytok)\n $ export OAUTH2_ACCESS_TOKENS=mytok=$MY_TOKEN\n $ ./myapp.py # start my local Python app using the tokens library\n\n\nReleasing\n=========\n\nUploading a new version to PyPI:\n\n.. code-block:: bash\n\n $ ./release.sh <NEW-VERSION>",
"bugtrack_url": null,
"license": "Apache License Version 2.0",
"summary": "Python library to manage OAuth access tokens",
"version": "1.1.19",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/zalando-stups/python-tokens"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "70dd4fd77cb049b7f1e7da1abc857a8638e07dc67224acf9ebde1f02e33167ae",
"md5": "2fd3a4bfa36d6251ec0bf5ad368242b0",
"sha256": "317f4386763bac9dd5c0a4c8b0f9f0238dc3fa81de3c6fd1971b6b01662b5750"
},
"downloads": -1,
"filename": "stups_tokens-1.1.19-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2fd3a4bfa36d6251ec0bf5ad368242b0",
"packagetype": "bdist_wheel",
"python_version": "3.5",
"requires_python": null,
"size": 6124,
"upload_time": "2017-01-04T17:23:57",
"upload_time_iso_8601": "2017-01-04T17:23:57.247263Z",
"url": "https://files.pythonhosted.org/packages/70/dd/4fd77cb049b7f1e7da1abc857a8638e07dc67224acf9ebde1f02e33167ae/stups_tokens-1.1.19-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "80bbd9b6991f59b7542ed6de9837e9160af066f6f47fb9515a412f0311315d2f",
"md5": "d8223ec9d8776d54ed4016fcf448d350",
"sha256": "7830ad83ccbfd52a9734608ffcefcca917137ce9480cc91a4fbd321a4aca3160"
},
"downloads": -1,
"filename": "stups-tokens-1.1.19.tar.gz",
"has_sig": false,
"md5_digest": "d8223ec9d8776d54ed4016fcf448d350",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4545,
"upload_time": "2017-01-04T17:23:55",
"upload_time_iso_8601": "2017-01-04T17:23:55.540057Z",
"url": "https://files.pythonhosted.org/packages/80/bb/d9b6991f59b7542ed6de9837e9160af066f6f47fb9515a412f0311315d2f/stups-tokens-1.1.19.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2017-01-04 17:23:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zalando-stups",
"github_project": "python-tokens",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.7.0"
]
]
}
],
"tox": true,
"lcname": "stups-tokens"
}