Skip to main content

tcpw

tcpw (TCP Wait) is a tool that waits until TCP endpoints are open.

It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers.

That is yet another alternative to wait-for-it.sh.

Rationale

  • available as a binary executable without any dependencies (file size <1M).
  • available on PyPI (x86_64 only)
  • additionally, you can set:
    • more than one endpoint: -a google.com:80 -a booble.gum:8080 ...
    • command, which can be executed only after success, failure or any result: -on f -a google.com:9999 echo "Endpoint is down"
    • polling interval: -i 500ms
    • timeout/interval in different time units: ns,ms,s,m,h

Installation

Download executable file:

sh -c "wget -O tcpw https://raw.githubusercontent.com/jackcvr/tcpw/main/bin/$(uname -m)/tcpw && chmod +x tcpw"

or:

pip install tcpw

PyPI - Version PyPI - Python Version

Usage

Usage: tcpw [-t timeout] [-i interval] [-on (s|f|any)] [-q] [-v] [-a host:port ...] [command [args]]

  -a value
    	Endpoint to await, in the form 'host:port'
  -i duration
    	Interval between retries in format N{ns,ms,s,m,h} (default 1s)
  -on string
    	Condition for command execution. Possible values: 's' - after success, 'f' - after failure, 'any' - always (default "s")
  -q	Do not print anything (default false)
  -t duration
    	Timeout in format N{ns,ms,s,m,h}, e.g. '5s' == 5 seconds. Zero for no timeout (default 0)
  -v	Verbose mode (default false)
  command args
    	Execute command with arguments after the test finishes (default: if connection succeeded)

Examples

Wait 5 seconds for port 80 on www.google.com, and if it is available, echo the message Google is up:

$ tcpw -t 5s -a www.google.com:80 echo "Google is up"
2024/08/26 20:06:47.209012 successfully connected to www.google.com:80
Google is up

Next command waits 2 seconds for www.google.com:80 and localhost:5000, checking them every 500 milliseconds with enabled verbose mode and executes echo regardless of the result:

$ tcpw -t 2s -i 500ms -v -on any -a www.google.com:80 -a localhost:5000 echo "Printed anyway"
2024/08/26 20:08:24.153240 connecting to localhost:5000...
2024/08/26 20:08:24.153327 connecting to www.google.com:80...
2024/08/26 20:08:24.153541 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:24.179927 successfully connected to www.google.com:80
2024/08/26 20:08:24.654984 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:25.155997 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:25.661397 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:26.161613 dial tcp: lookup localhost: i/o timeout
timeout error
Printed anyway

License

MIT

Metadata

Release files for tcpw 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tcpw 0.1.10
File Size Uploaded Provenance Actions
tcpw-0.1.10.tar.gz 896.5 kB Without provenance Details for tcpw-0.1.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tcpw 0.1.10
File Interpreter ABI Platform Actions
tcpw-0.1.10-py3-none-any.whl Python 3 none any Details for tcpw-0.1.10-py3-none-any.whl

Total release size: 1.8 MB

Release files / tcpw-0.1.10.tar.gz

Download URL tcpw-0.1.10.tar.gz
Size 896.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2ea2f6950fc9bad26a022918c6aa9b1918ea4dd7b85a7e6da0e988a490c1f448
BLAKE2b-256 checksum
How to use checksums
8be587997d1bf130767160bdf940a9c986ebafce08721a295e7ffeead9ffbf24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / tcpw-0.1.10-py3-none-any.whl

Download URL tcpw-0.1.10-py3-none-any.whl
Size 893.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f61ff6701809442ff1e79cf9d6d256a5d8434fff2bfa96de9d6bc2291bb2388e
BLAKE2b-256 checksum
How to use checksums
1de176d92b60a4b1aae6734858c1918158dc3cdc628c25717fe886c2001b8f57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for tcpw 0.1.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page