jupyterhub-credit-service


Namejupyterhub-credit-service JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryJupyterHub Credit Servce
upload_time2025-10-20 07:24:37
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD 3-Clause License Copyright (c) 2025, Tim Kreuzer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords jupyterhub
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JupyterHub Credit Service

[![Documentation](https://img.shields.io/badge/Documentation-passed-green)](https://jsc-jupyter.github.io/jupyterhub-credit-service/)
[![PyPI Test Action](https://github.com/jsc-jupyter/jupyterhub-credit-service/actions/workflows/pytest.yml/badge.svg?branch=main)](https://github.com/jsc-jupyter/jupyterhub-credit-service/actions/workflows/pytest.yml)
[![PyPI](https://img.shields.io/pypi/v/jupyterhub-credit-service)](https://pypi.org/project/jupyterhub-credit-service/)

---

## Overview

The **JupyterHub Credit Service** is a python package that can be installed as an extension to JupyterHub. It introduces a lightweight, flexible system to limit **resource consumption** on a **per-user** and/or **per-project** model.

It enables administrators to control how long users can use computational environments, and how shared project resources are allocated — all without complex accounting or billing systems.

<div style="text-align: center;">
  <img src="https://jsc-jupyter.github.io/jupyterhub-credit-service/images/image_home.png" alt="JupyterHub" style="width: 100%;">
</div>

---

## Installation

You can install the package directly from PyPI:

```bash
pip install jupyterhub-credit-service
```

---

## Configuration

For detailed information, please visit the [documentation site](https://jsc-jupyter.github.io/jupyterhub-credit-service/).

Example `jupyterhub_config.py`:

```python
import jupyterhub_credit_service

# Configure Authenticator
from oauthenticator.generic import GenericOAuthenticator
# Use any Authenticator you usually use together with the CreditsAuthenticator
class MixinAuthenticator(GenericOAuthenticator, jupyterhub_credit_service.CreditsAuthenticator):
    pass

c.JupyterHub.authenticator_class = MixinAuthenticator

# Different users may get different amount of credits
def user_cap(username, user_groups=[], is_admin=False):
    if username.endswith("mycompany.org"):
        return 1000
    elif username.endswith("googlemail.com") or username.endswith("gmail.com"):
        return 30
    return 100

c.MixinAuthenticator.credits_user_cap = user_cap  # may be a callable or integer
c.MixinAuthenticator.credits_user_grant_value = 5 # may be a callable or integer
c.MixinAuthenticator.credits_user_grant_interval = 600 # Gain 5 credits every 10 minutes, may be a callable or integer

c.MixinAuthenticator.userinfo_url = ... # your normal configuration


# Configure Spawner
import kubespawner
# You can reuse the "KubeSpawner" name so you don't have to change your other configs
class KubeSpawner(kubespawner.KubeSpawner, jupyterhub_credit_service.CreditsSpawner):
    pass

def get_billing_value(spawner):
    # Costs gpus*10 credits + 5 credits, per billing_interval
    billing_value = 5
    if "gpus" in spawner.user_options.keys():
        billing_value += spawner.user_options["gpus"] * 10
    return billing_value

c.JupyterHub.spawner_class = KubeSpawner
c.KubeSpawner.billing_value = get_billing_value # may be a callable or integer
c.KubeSpawner.billing_interval = 600 # Pay credits depending on gpus usage every 10 minutes, may be a callable or integer

# Show JupyterHub Credits in the Header in your frontend
c.JupyterHub.template_paths = jupyterhub_credit_service.template_paths
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jupyterhub-credit-service",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "jupyterhub",
    "author": null,
    "author_email": "Tim Kreuzer <t.kreuzer@fz-juelich.de>",
    "download_url": "https://files.pythonhosted.org/packages/d2/05/b3b8fd534118c8df23ada789cd7d28042b4cd5d4455066348933dc01ba1b/jupyterhub_credit_service-0.1.3.tar.gz",
    "platform": null,
    "description": "# JupyterHub Credit Service\n\n[![Documentation](https://img.shields.io/badge/Documentation-passed-green)](https://jsc-jupyter.github.io/jupyterhub-credit-service/)\n[![PyPI Test Action](https://github.com/jsc-jupyter/jupyterhub-credit-service/actions/workflows/pytest.yml/badge.svg?branch=main)](https://github.com/jsc-jupyter/jupyterhub-credit-service/actions/workflows/pytest.yml)\n[![PyPI](https://img.shields.io/pypi/v/jupyterhub-credit-service)](https://pypi.org/project/jupyterhub-credit-service/)\n\n---\n\n## Overview\n\nThe **JupyterHub Credit Service** is a python package that can be installed as an extension to JupyterHub. It introduces a lightweight, flexible system to limit **resource consumption** on a **per-user** and/or **per-project** model.\n\nIt enables administrators to control how long users can use computational environments, and how shared project resources are allocated \u2014 all without complex accounting or billing systems.\n\n<div style=\"text-align: center;\">\n  <img src=\"https://jsc-jupyter.github.io/jupyterhub-credit-service/images/image_home.png\" alt=\"JupyterHub\" style=\"width: 100%;\">\n</div>\n\n---\n\n## Installation\n\nYou can install the package directly from PyPI:\n\n```bash\npip install jupyterhub-credit-service\n```\n\n---\n\n## Configuration\n\nFor detailed information, please visit the [documentation site](https://jsc-jupyter.github.io/jupyterhub-credit-service/).\n\nExample `jupyterhub_config.py`:\n\n```python\nimport jupyterhub_credit_service\n\n# Configure Authenticator\nfrom oauthenticator.generic import GenericOAuthenticator\n# Use any Authenticator you usually use together with the CreditsAuthenticator\nclass MixinAuthenticator(GenericOAuthenticator, jupyterhub_credit_service.CreditsAuthenticator):\n    pass\n\nc.JupyterHub.authenticator_class = MixinAuthenticator\n\n# Different users may get different amount of credits\ndef user_cap(username, user_groups=[], is_admin=False):\n    if username.endswith(\"mycompany.org\"):\n        return 1000\n    elif username.endswith(\"googlemail.com\") or username.endswith(\"gmail.com\"):\n        return 30\n    return 100\n\nc.MixinAuthenticator.credits_user_cap = user_cap  # may be a callable or integer\nc.MixinAuthenticator.credits_user_grant_value = 5 # may be a callable or integer\nc.MixinAuthenticator.credits_user_grant_interval = 600 # Gain 5 credits every 10 minutes, may be a callable or integer\n\nc.MixinAuthenticator.userinfo_url = ... # your normal configuration\n\n\n# Configure Spawner\nimport kubespawner\n# You can reuse the \"KubeSpawner\" name so you don't have to change your other configs\nclass KubeSpawner(kubespawner.KubeSpawner, jupyterhub_credit_service.CreditsSpawner):\n    pass\n\ndef get_billing_value(spawner):\n    # Costs gpus*10 credits + 5 credits, per billing_interval\n    billing_value = 5\n    if \"gpus\" in spawner.user_options.keys():\n        billing_value += spawner.user_options[\"gpus\"] * 10\n    return billing_value\n\nc.JupyterHub.spawner_class = KubeSpawner\nc.KubeSpawner.billing_value = get_billing_value # may be a callable or integer\nc.KubeSpawner.billing_interval = 600 # Pay credits depending on gpus usage every 10 minutes, may be a callable or integer\n\n# Show JupyterHub Credits in the Header in your frontend\nc.JupyterHub.template_paths = jupyterhub_credit_service.template_paths\n```\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License\n        \n        Copyright (c) 2025, Tim Kreuzer\n        All rights reserved.\n        \n        Redistribution and use in source and binary forms, with or without\n        modification, are permitted provided that the following conditions are met:\n        \n        1. Redistributions of source code must retain the above copyright notice, this\n           list of conditions and the following disclaimer.\n        \n        2. Redistributions in binary form must reproduce the above copyright notice,\n           this list of conditions and the following disclaimer in the documentation\n           and/or other materials provided with the distribution.\n        \n        3. Neither the name of the copyright holder nor the names of its\n           contributors may be used to endorse or promote products derived from\n           this software without specific prior written permission.\n        \n        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "JupyterHub Credit Servce",
    "version": "0.1.3",
    "project_urls": {
        "Documentation": "https://github.com/jsc-jupyter/jupyterhub-credit-service#readme",
        "Issues": "https://github.com/jsc-jupyter/jupyterhub-credit-service/issues",
        "Source": "https://github.com/jsc-jupyter/jupyterhub-credit-service"
    },
    "split_keywords": [
        "jupyterhub"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "248f4cdc35be2a56e0fd79234a3629ec418b10e39fe2888b9c3e05c2ad717246",
                "md5": "c17088d15b142357c1e61e5e1a860ad0",
                "sha256": "065d389e8ff82dda9966f9a4739fb5d0683832d07e466a2538535689424e6932"
            },
            "downloads": -1,
            "filename": "jupyterhub_credit_service-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c17088d15b142357c1e61e5e1a860ad0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18148,
            "upload_time": "2025-10-20T07:24:35",
            "upload_time_iso_8601": "2025-10-20T07:24:35.751080Z",
            "url": "https://files.pythonhosted.org/packages/24/8f/4cdc35be2a56e0fd79234a3629ec418b10e39fe2888b9c3e05c2ad717246/jupyterhub_credit_service-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d205b3b8fd534118c8df23ada789cd7d28042b4cd5d4455066348933dc01ba1b",
                "md5": "7a031d32e3aa760795725db28a0d00bb",
                "sha256": "9366f536e552f2c7c71b6fb7806565d00014263345571b492b2bcffb72fc54e0"
            },
            "downloads": -1,
            "filename": "jupyterhub_credit_service-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "7a031d32e3aa760795725db28a0d00bb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 27097,
            "upload_time": "2025-10-20T07:24:37",
            "upload_time_iso_8601": "2025-10-20T07:24:37.175774Z",
            "url": "https://files.pythonhosted.org/packages/d2/05/b3b8fd534118c8df23ada789cd7d28042b4cd5d4455066348933dc01ba1b/jupyterhub_credit_service-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-20 07:24:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jsc-jupyter",
    "github_project": "jupyterhub-credit-service#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jupyterhub-credit-service"
}
        
Elapsed time: 1.83778s