Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A CLI utility for blocking until a service is listening

Project Description

I needed a way to block my app from starting until the database service was running and accepting connections. This was particularly a problem when using Docker and docker-compose. You can run this utility as part of a or script and it will block for 15 seconds (configurable) until it can connect to the hostname and port as specified in your connection URL (gleaned from DATABASE_URL environment variable by default).


$ pip install urlwait


$ urlwait --help


    $ urlwait [SERVICE URL] [TIMEOUT]

    SERVICE URL is a connection url, e.g. a typical value for $DATABASE_URL. TIMEOUT is
    a number of seconds to try to connect to the host and port specified in the SERVICE
    URL. These values may also be specified in environment variables, but command line
    args take precedence:

        URLWAIT_VARNAME: the env var name containing the URL to check. Default DATABASE_URL.
        URLWAIT_TIMEOUT: the number of seconds to wait. Default 15.

    Returns a 0 status if the connection completed successfully before the timeout, or 1 if not.
    It is designed for use with Docker or other dev or testing environments where the connected
    services and the app are started simultaneously, but one should wait for the other.


    The following are equivalent:

    $ urlwait redis://localhost:6379/0 20
    $ urlwait $CACHE_URL 20

The module is also usable in your python code:

import os

from urlwait import wait_for_url

if wait_for_url(os.getenv('REDIS_URL')):
    # do things with the service
    # service likely did not start

If you don’t have the service URL but do have the host and port, you can use the wait_for_service(host, port, timeout) function instead.


  • 0.4 - 2017-03-02 - Always return true if protocol is sqlite

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(6.3 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Mar 2, 2017
(4.9 kB) Copy SHA256 Hash SHA256
Source None Mar 2, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate