Application configuration#

Module: jupyterhub.app#

The multi-user notebook application

JupyterHub#

class jupyterhub.app.JupyterHub(**kwargs: Any)#

An Application for starting a Multi-User Jupyter Notebook server.

active_server_limit c.JupyterHub.active_server_limit = Int(0)#

Maximum number of concurrent servers that can be active at a time.

Setting this can limit the total resources your users can consume.

An active server is any server that’s not fully stopped. It is considered active from the time it has been requested until the time that it has completely stopped.

If this many user servers are active, users will not be able to launch new servers until a server is shutdown. Spawn requests will be rejected with a 429 error asking them to try again.

If set to 0, no limit is enforced.

active_user_window c.JupyterHub.active_user_window = Int(1800)#

Duration (in seconds) to determine the number of active users.

activity_resolution c.JupyterHub.activity_resolution = Int(30)#

Resolution (in seconds) for updating activity

If activity is registered that is less than activity_resolution seconds more recent than the current value, the new value will be ignored.

This avoids too many writes to the Hub database.

admin_access c.JupyterHub.admin_access = Bool(False)#

DEPRECATED since version 2.0.0.

The default admin role has full permissions, use custom RBAC scopes instead to create restricted administrator roles. https://jupyterhub.readthedocs.io/en/stable/rbac/index.html

admin_users c.JupyterHub.admin_users = Set()#

DEPRECATED since version 0.7.2, use Authenticator.admin_users instead.

allow_named_servers c.JupyterHub.allow_named_servers = Bool(False)#

Allow named single-user servers per user

answer_yes c.JupyterHub.answer_yes = Bool(False)#

Answer yes to any questions (e.g. confirm overwrite)

api_page_default_limit c.JupyterHub.api_page_default_limit = Int(50)#

The default amount of records returned by a paginated endpoint

api_page_max_limit c.JupyterHub.api_page_max_limit = Int(200)#

The maximum amount of records that can be returned at once

api_tokens c.JupyterHub.api_tokens = Dict()#

PENDING DEPRECATION: consider using services

Dict of token:username to be loaded into the database.

Allows ahead-of-time generation of API tokens for use by externally managed services, which authenticate as JupyterHub users.

Consider using services for general services that talk to the JupyterHub API.

authenticate_prometheus c.JupyterHub.authenticate_prometheus = Bool(True)#

Authentication for prometheus metrics

authenticator_class c.JupyterHub.authenticator_class = EntryPointType(<class 'jupyterhub.auth.PAMAuthenticator'>)#

Class for authenticating users.

This should be a subclass of jupyterhub.auth.Authenticator

with an authenticate() method that:

  • is a coroutine (asyncio or tornado)

  • returns username on success, None on failure

  • takes two arguments: (handler, data), where handler is the calling web.RequestHandler, and data is the POST form data from the login page.

Changed in version 1.0: authenticators may be registered via entry points, e.g. c.JupyterHub.authenticator_class = 'pam'

Currently installed:
  • default: jupyterhub.auth.PAMAuthenticator

  • dummy: jupyterhub.auth.DummyAuthenticator

  • null: jupyterhub.auth.NullAuthenticator

  • pam: jupyterhub.auth.PAMAuthenticator

base_url c.JupyterHub.base_url = URLPrefix('/')#

The base URL of the entire application.

Add this to the beginning of all JupyterHub URLs. Use base_url to run JupyterHub within an existing website.

bind_url c.JupyterHub.bind_url = Unicode('http://:8000')#

The public facing URL of the whole JupyterHub application.

This is the address on which the proxy will bind. Sets protocol, ip, base_url

cleanup_proxy c.JupyterHub.cleanup_proxy = Bool(True)#

Whether to shutdown the proxy when the Hub shuts down.

Disable if you want to be able to teardown the Hub while leaving the proxy running.

Only valid if the proxy was starting by the Hub process.

If both this and cleanup_servers are False, sending SIGINT to the Hub will only shutdown the Hub, leaving everything else running.

The Hub should be able to resume from database state.

cleanup_servers c.JupyterHub.cleanup_servers = Bool(True)#

Whether to shutdown single-user servers when the Hub shuts down.

Disable if you want to be able to teardown the Hub while leaving the single-user servers running.

If both this and cleanup_proxy are False, sending SIGINT to the Hub will only shutdown the Hub, leaving everything else running.

The Hub should be able to resume from database state.

concurrent_spawn_limit c.JupyterHub.concurrent_spawn_limit = Int(100)#

Maximum number of concurrent users that can be spawning at a time.

Spawning lots of servers at the same time can cause performance problems for the Hub or the underlying spawning system. Set this limit to prevent bursts of logins from attempting to spawn too many servers at the same time.

This does not limit the number of total running servers. See active_server_limit for that.

If more than this many users attempt to spawn at a time, their requests will be rejected with a 429 error asking them to try again. Users will have to wait for some of the spawning services to finish starting before they can start their own.

If set to 0, no limit is enforced.

config_file c.JupyterHub.config_file = Unicode('jupyterhub_config.py')#

The config file to load

confirm_no_ssl c.JupyterHub.confirm_no_ssl = Bool(False)#

DEPRECATED: does nothing

cookie_max_age_days c.JupyterHub.cookie_max_age_days = Float(14)#

Number of days for a login cookie to be valid. Default is two weeks.

cookie_secret c.JupyterHub.cookie_secret = Union()#

The cookie secret to use to encrypt cookies.

Loaded from the JPY_COOKIE_SECRET env variable by default.

Should be exactly 256 bits (32 bytes).

cookie_secret_file c.JupyterHub.cookie_secret_file = Unicode('jupyterhub_cookie_secret')#

File in which to store the cookie secret.

custom_scopes c.JupyterHub.custom_scopes = Dict()#

Custom scopes to define.

For use when defining custom roles, to grant users granular permissions

All custom scopes must have a description, and must start with the prefix custom:.

For example:

custom_scopes = {
    "custom:jupyter_server:read": {
        "description": "read-only access to a single-user server",
    },
}
data_files_path c.JupyterHub.data_files_path = Unicode('')#

The location of jupyterhub data files (e.g. /usr/local/share/jupyterhub)

db_kwargs c.JupyterHub.db_kwargs = Dict()#

Include any kwargs to pass to the database connection. See sqlalchemy.create_engine for details.

db_url c.JupyterHub.db_url = Unicode('sqlite:///jupyterhub.sqlite')#

url for the database. e.g. sqlite:///jupyterhub.sqlite

debug_db c.JupyterHub.debug_db = Bool(False)#

log all database transactions. This has A LOT of output

debug_proxy c.JupyterHub.debug_proxy = Bool(False)#

DEPRECATED since version 0.8: Use ConfigurableHTTPProxy.debug

default_server_name c.JupyterHub.default_server_name = Unicode('')#

If named servers are enabled, default name of server to spawn or open when no server is specified, e.g. by user-redirect.

Note: This has no effect if named servers are not enabled, and does _not_ change the existence or behavior of the default server named '' (the empty string). This only affects which named server is launched when no server is specified, e.g. by links to /hub/user-redirect/lab/tree/mynotebook.ipynb.

default_url c.JupyterHub.default_url = Union()#

The default URL for users when they arrive (e.g. when user directs to “/”)

By default, redirects users to their own server.

Can be a Unicode string (e.g. ‘/hub/home’) or a callable based on the handler object:

def default_url_fn(handler):
    user = handler.current_user
    if user and user.admin:
        return '/hub/admin'
    return '/hub/home'

c.JupyterHub.default_url = default_url_fn
external_ssl_authorities c.JupyterHub.external_ssl_authorities = Dict()#

Dict authority:dict(files). Specify the key, cert, and/or ca file for an authority. This is useful for externally managed proxies that wish to use internal_ssl.

The files dict has this format (you must specify at least a cert):

{
    'key': '/path/to/key.key',
    'cert': '/path/to/cert.crt',
    'ca': '/path/to/ca.crt'
}

The authorities you can override: ‘hub-ca’, ‘notebooks-ca’, ‘proxy-api-ca’, ‘proxy-client-ca’, and ‘services-ca’.

Use with internal_ssl

extra_handlers c.JupyterHub.extra_handlers = List()#

DEPRECATED.

If you need to register additional HTTP endpoints please use services instead.

extra_log_file c.JupyterHub.extra_log_file = Unicode('')#

DEPRECATED: use output redirection instead, e.g.

jupyterhub &>> /var/log/jupyterhub.log

extra_log_handlers c.JupyterHub.extra_log_handlers = List()#

Extra log handlers to set on JupyterHub logger

forwarded_host_header c.JupyterHub.forwarded_host_header = Unicode('')#

Alternate header to use as the Host (e.g., X-Forwarded-Host) when determining whether a request is cross-origin

This may be useful when JupyterHub is running behind a proxy that rewrites the Host header.

generate_certs c.JupyterHub.generate_certs = Bool(False)#

Generate certs used for internal ssl

generate_config c.JupyterHub.generate_config = Bool(False)#

Generate default config file

hub_bind_url c.JupyterHub.hub_bind_url = Unicode('')#

The URL on which the Hub will listen. This is a private URL for internal communication. Typically set in combination with hub_connect_url. If a unix socket, hub_connect_url must also be set.

For example:

http://127.0.0.1:8081” “unix+http://%2Fsrv%2Fjupyterhub%2Fjupyterhub.sock”

New in version 0.9.

hub_connect_ip c.JupyterHub.hub_connect_ip = Unicode('')#

The ip or hostname for proxies and spawners to use for connecting to the Hub.

Use when the bind address (hub_ip) is 0.0.0.0, :: or otherwise different from the connect address.

Default: when hub_ip is 0.0.0.0 or ::, use socket.gethostname(), otherwise use hub_ip.

Note: Some spawners or proxy implementations might not support hostnames. Check your spawner or proxy documentation to see if they have extra requirements.

New in version 0.8.

hub_connect_port c.JupyterHub.hub_connect_port = Int(0)#

DEPRECATED

Use hub_connect_url

New in version 0.8.

Deprecated since version 0.9: Use hub_connect_url

hub_connect_url c.JupyterHub.hub_connect_url = Unicode('')#

The URL for connecting to the Hub. Spawners, services, and the proxy will use this URL to talk to the Hub.

Only needs to be specified if the default hub URL is not connectable (e.g. using a unix+http:// bind url).

See also

JupyterHub.hub_connect_ip JupyterHub.hub_bind_url

New in version 0.9.

hub_ip c.JupyterHub.hub_ip = Unicode('127.0.0.1')#

The ip address for the Hub process to bind to.

By default, the hub listens on localhost only. This address must be accessible from the proxy and user servers. You may need to set this to a public ip or ‘’ for all interfaces if the proxy or user servers are in containers or on a different host.

See hub_connect_ip for cases where the bind and connect address should differ, or hub_bind_url for setting the full bind URL.

hub_port c.JupyterHub.hub_port = Int(8081)#

The internal port for the Hub process.

This is the internal port of the hub itself. It should never be accessed directly. See JupyterHub.port for the public port to use when accessing jupyterhub. It is rare that this port should be set except in cases of port conflict.

See also hub_ip for the ip and hub_bind_url for setting the full bind URL.

hub_routespec c.JupyterHub.hub_routespec = Unicode('/')#

The routing prefix for the Hub itself.

Override to send only a subset of traffic to the Hub. Default is to use the Hub as the default route for all requests.

This is necessary for normal jupyterhub operation, as the Hub must receive requests for e.g. /user/:name when the user’s server is not running.

However, some deployments using only the JupyterHub API may want to handle these events themselves, in which case they can register their own default target with the proxy and set e.g. hub_routespec = /hub/ to serve only the hub’s own pages, or even /hub/api/ for api-only operation.

Note: hub_routespec must include the base_url, if any.

New in version 1.4.

implicit_spawn_seconds c.JupyterHub.implicit_spawn_seconds = Float(0)#

Trigger implicit spawns after this many seconds.

When a user visits a URL for a server that’s not running, they are shown a page indicating that the requested server is not running with a button to spawn the server.

Setting this to a positive value will redirect the user after this many seconds, effectively clicking this button automatically for the users, automatically beginning the spawn process.

Warning: this can result in errors and surprising behavior when sharing access URLs to actual servers, since the wrong server is likely to be started.

init_spawners_timeout c.JupyterHub.init_spawners_timeout = Int(10)#

Timeout (in seconds) to wait for spawners to initialize

Checking if spawners are healthy can take a long time if many spawners are active at hub start time.

If it takes longer than this timeout to check, init_spawner will be left to complete in the background and the http server is allowed to start.

A timeout of -1 means wait forever, which can mean a slow startup of the Hub but ensures that the Hub is fully consistent by the time it starts responding to requests. This matches the behavior of jupyterhub 1.0.

internal_certs_location c.JupyterHub.internal_certs_location = Unicode('internal-ssl')#

The location to store certificates automatically created by JupyterHub.

Use with internal_ssl

internal_ssl c.JupyterHub.internal_ssl = Bool(False)#

Enable SSL for all internal communication

This enables end-to-end encryption between all JupyterHub components. JupyterHub will automatically create the necessary certificate authority and sign notebook certificates as they’re created.

ip c.JupyterHub.ip = Unicode('')#

The public facing ip of the whole JupyterHub application (specifically referred to as the proxy).

This is the address on which the proxy will listen. The default is to listen on all interfaces. This is the only address through which JupyterHub should be accessed by users.

jinja_environment_options c.JupyterHub.jinja_environment_options = Dict()#

Supply extra arguments that will be passed to Jinja environment.

last_activity_interval c.JupyterHub.last_activity_interval = Int(300)#

Interval (in seconds) at which to update last-activity timestamps.

load_groups c.JupyterHub.load_groups = Dict()#

Dict of ‘group’: [‘usernames’] to load at startup.

This strictly adds groups and users to groups.

Loading one set of groups, then starting JupyterHub again with a different set will not remove users or groups from previous launches. That must be done through the API.

load_roles c.JupyterHub.load_roles = List()#

List of predefined role dictionaries to load at startup.

For instance:

load_roles = [
                {
                    'name': 'teacher',
                    'description': 'Access to users' information and group membership',
                    'scopes': ['users', 'groups'],
                    'users': ['cyclops', 'gandalf'],
                    'services': [],
                    'groups': []
                }
            ]

All keys apart from ‘name’ are optional. See all the available scopes in the JupyterHub REST API documentation.

Default roles are defined in roles.py.

log_datefmt c.JupyterHub.log_datefmt = Unicode('%Y-%m-%d %H:%M:%S')#

The date format used by logging formatters for %(asctime)s

log_format c.JupyterHub.log_format = Unicode('[%(name)s]%(highlevel)s %(message)s')#

The Logging format template

log_level c.JupyterHub.log_level = Enum(30)#

Set the log level by value or name.

logging_config c.JupyterHub.logging_config = Dict()#

Configure additional log handlers.

The default stderr logs handler is configured by the log_level, log_datefmt and log_format settings.

This configuration can be used to configure additional handlers (e.g. to output the log to a file) or for finer control over the default handlers.

If provided this should be a logging configuration dictionary, for more information see: https://docs.python.org/3/library/logging.config.html#logging-config-dictschema

This dictionary is merged with the base logging configuration which defines the following:

  • A logging formatter intended for interactive use called console.

  • A logging handler that writes to stderr called console which uses the formatter console.

  • A logger with the name of this application set to DEBUG level.

This example adds a new handler that writes to a file:

c.Application.logging_config = {
    'handlers': {
        'file': {
            'class': 'logging.FileHandler',
            'level': 'DEBUG',
            'filename': '<path/to/file>',
        }
    },
    'loggers': {
        '<application-name>': {
            'level': 'DEBUG',
            # NOTE: if you don't list the default "console"
            # handler here then it will be disabled
            'handlers': ['console', 'file'],
        },
    }
}
logo_file c.JupyterHub.logo_file = Unicode('')#

Specify path to a logo image to override the Jupyter logo in the banner.

named_server_limit_per_user c.JupyterHub.named_server_limit_per_user = Union(0)#

Maximum number of concurrent named servers that can be created by a user at a time.

Setting this can limit the total resources a user can consume.

If set to 0, no limit is enforced.

Can be an integer or a callable/awaitable based on the handler object:

def named_server_limit_per_user_fn(handler):
    user = handler.current_user
    if user and user.admin:
        return 0
    return 5

c.JupyterHub.named_server_limit_per_user = named_server_limit_per_user_fn
oauth_token_expires_in c.JupyterHub.oauth_token_expires_in = Int(0)#

Expiry (in seconds) of OAuth access tokens.

The default is to expire when the cookie storing them expires, according to cookie_max_age_days config.

These are the tokens stored in cookies when you visit a single-user server or service. When they expire, you must re-authenticate with the Hub, even if your Hub authentication is still valid. If your Hub authentication is valid, logging in may be a transparent redirect as you refresh the page.

This does not affect JupyterHub API tokens in general, which do not expire by default. Only tokens issued during the oauth flow accessing services and single-user servers are affected.

New in version 1.4: OAuth token expires_in was not previously configurable.

Changed in version 1.4: Default now uses cookie_max_age_days so that oauth tokens which are generally stored in cookies, expire when the cookies storing them expire. Previously, it was one hour.

pid_file c.JupyterHub.pid_file = Unicode('')#

File to write PID Useful for daemonizing JupyterHub.

port c.JupyterHub.port = Int(8000)#

The public facing port of the proxy.

This is the port on which the proxy will listen. This is the only port through which JupyterHub should be accessed by users.

proxy_api_ip c.JupyterHub.proxy_api_ip = Unicode('')#

DEPRECATED since version 0.8 : Use ConfigurableHTTPProxy.api_url

proxy_api_port c.JupyterHub.proxy_api_port = Int(0)#

DEPRECATED since version 0.8 : Use ConfigurableHTTPProxy.api_url

proxy_auth_token c.JupyterHub.proxy_auth_token = Unicode('')#

DEPRECATED since version 0.8: Use ConfigurableHTTPProxy.auth_token

proxy_check_interval c.JupyterHub.proxy_check_interval = Int(5)#

DEPRECATED since version 0.8: Use ConfigurableHTTPProxy.check_running_interval

proxy_class c.JupyterHub.proxy_class = EntryPointType(<class 'jupyterhub.proxy.ConfigurableHTTPProxy'>)#

The class to use for configuring the JupyterHub proxy.

Should be a subclass of jupyterhub.proxy.Proxy.

Changed in version 1.0: proxies may be registered via entry points, e.g. c.JupyterHub.proxy_class = 'traefik'

Currently installed:
  • configurable-http-proxy: jupyterhub.proxy.ConfigurableHTTPProxy

  • default: jupyterhub.proxy.ConfigurableHTTPProxy

proxy_cmd c.JupyterHub.proxy_cmd = Command()#

DEPRECATED since version 0.8. Use ConfigurableHTTPProxy.command

recreate_internal_certs c.JupyterHub.recreate_internal_certs = Bool(False)#

Recreate all certificates used within JupyterHub on restart.

Note: enabling this feature requires restarting all notebook servers.

Use with internal_ssl

redirect_to_server c.JupyterHub.redirect_to_server = Bool(True)#

Redirect user to server (if running), instead of control panel.

reset_db c.JupyterHub.reset_db = Bool(False)#

Purge and reset the database.

service_check_interval c.JupyterHub.service_check_interval = Int(60)#

Interval (in seconds) at which to check connectivity of services with web endpoints.

service_tokens c.JupyterHub.service_tokens = Dict()#

Dict of token:servicename to be loaded into the database.

Allows ahead-of-time generation of API tokens for use by externally managed services.

services c.JupyterHub.services = List()#

List of service specification dictionaries.

A service

For instance:

services = [
    {
        'name': 'cull_idle',
        'command': ['/path/to/cull_idle_servers.py'],
    },
    {
        'name': 'formgrader',
        'url': 'http://127.0.0.1:1234',
        'api_token': 'super-secret',
        'environment':
    }
]
show_config c.JupyterHub.show_config = Bool(False)#

Instead of starting the Application, dump configuration to stdout

show_config_json c.JupyterHub.show_config_json = Bool(False)#

Instead of starting the Application, dump configuration to stdout (as JSON)

shutdown_on_logout c.JupyterHub.shutdown_on_logout = Bool(False)#

Shuts down all user servers on logout

spawner_class c.JupyterHub.spawner_class = EntryPointType(<class 'jupyterhub.spawner.LocalProcessSpawner'>)#

The class to use for spawning single-user servers.

Should be a subclass of jupyterhub.spawner.Spawner.

Changed in version 1.0: spawners may be registered via entry points, e.g. c.JupyterHub.spawner_class = 'localprocess'

Currently installed:
  • default: jupyterhub.spawner.LocalProcessSpawner

  • localprocess: jupyterhub.spawner.LocalProcessSpawner

  • simple: jupyterhub.spawner.SimpleLocalProcessSpawner

ssl_cert c.JupyterHub.ssl_cert = Unicode('')#

Path to SSL certificate file for the public facing interface of the proxy

When setting this, you should also set ssl_key

ssl_key c.JupyterHub.ssl_key = Unicode('')#

Path to SSL key file for the public facing interface of the proxy

When setting this, you should also set ssl_cert

statsd_host c.JupyterHub.statsd_host = Unicode('')#

Host to send statsd metrics to. An empty string (the default) disables sending metrics.

statsd_port c.JupyterHub.statsd_port = Int(8125)#

Port on which to send statsd metrics about the hub

statsd_prefix c.JupyterHub.statsd_prefix = Unicode('jupyterhub')#

Prefix to use for all metrics sent by jupyterhub to statsd

subdomain_host c.JupyterHub.subdomain_host = Unicode('')#

Run single-user servers on subdomains of this host.

This should be the full https://hub.domain.tld[:port].

Provides additional cross-site protections for javascript served by single-user servers.

Requires <username>.hub.domain.tld to resolve to the same host as hub.domain.tld.

In general, this is most easily achieved with wildcard DNS.

When using SSL (i.e. always) this also requires a wildcard SSL certificate.

template_paths c.JupyterHub.template_paths = List()#

Paths to search for jinja templates, before using the default templates.

template_vars c.JupyterHub.template_vars = Dict()#

Extra variables to be passed into jinja templates

tornado_settings c.JupyterHub.tornado_settings = Dict()#

Extra settings overrides to pass to the tornado application.

trust_user_provided_tokens c.JupyterHub.trust_user_provided_tokens = Bool(False)#

Trust user-provided tokens (via JupyterHub.service_tokens) to have good entropy.

If you are not inserting additional tokens via configuration file, this flag has no effect.

In JupyterHub 0.8, internally generated tokens do not pass through additional hashing because the hashing is costly and does not increase the entropy of already-good UUIDs.

User-provided tokens, on the other hand, are not trusted to have good entropy by default, and are passed through many rounds of hashing to stretch the entropy of the key (i.e. user-provided tokens are treated as passwords instead of random keys). These keys are more costly to check.

If your inserted tokens are generated by a good-quality mechanism, e.g. openssl rand -hex 32, then you can set this flag to True to reduce the cost of checking authentication tokens.

trusted_alt_names c.JupyterHub.trusted_alt_names = List()#

Names to include in the subject alternative name.

These names will be used for server name verification. This is useful if JupyterHub is being run behind a reverse proxy or services using ssl are on different hosts.

Use with internal_ssl

trusted_downstream_ips c.JupyterHub.trusted_downstream_ips = List()#

Downstream proxy IP addresses to trust.

This sets the list of IP addresses that are trusted and skipped when processing the X-Forwarded-For header. For example, if an external proxy is used for TLS termination, its IP address should be added to this list to ensure the correct client IP addresses are recorded in the logs instead of the proxy server’s IP address.

upgrade_db c.JupyterHub.upgrade_db = Bool(False)#

Upgrade the database automatically on start.

Only safe if database is regularly backed up. Only SQLite databases will be backed up to a local file automatically.

use_legacy_stopped_server_status_code c.JupyterHub.use_legacy_stopped_server_status_code = Bool(False)#

Return 503 rather than 424 when request comes in for a non-running server.

Prior to JupyterHub 2.0, we returned a 503 when any request came in for a user server that was currently not running. By default, JupyterHub 2.0 will return a 424 - this makes operational metric dashboards more useful.

JupyterLab < 3.2 expected the 503 to know if the user server is no longer running, and prompted the user to start their server. Set this config to true to retain the old behavior, so JupyterLab < 3.2 can continue to show the appropriate UI when the user server is stopped.

This option will be removed in a future release.

user_redirect_hook c.JupyterHub.user_redirect_hook = Callable(None)#

Callable to affect behavior of /user-redirect/

Receives 4 parameters: 1. path - URL path that was provided after /user-redirect/ 2. request - A Tornado HTTPServerRequest representing the current request. 3. user - The currently authenticated user. 4. base_url - The base_url of the current hub, for relative redirects

It should return the new URL to redirect to, or None to preserve current behavior.