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!

Simple Python Varnish socket interface

Project Description

A simple python library to administer Varnish over the administration socket. The library can use shared secret authentication. Almost all testing has been done against Varnish 2.1.5.

Note: To use the library with Varnish 2.0.6, set compat = True (Experimental)

This was heavily inspired by Tim Whitlock’s wonderful PHP library (


from varnish_admin_socket import VarnishAdminSocket
varnish = VarnishAdminSocket()

# Optionally set host, port, and secret
# host defaults to, port defaults to 6082, secret defaults to False = ''
varnish.port = 6082
# You probably want to add a newline, this is usually read from a file.
varnish.secret = "123\n"
# To load the secret key from a file set secret_file
varnish.secret_file = '/etc/varnish/secret.txt'
# To use with Varnish 2.0.6 compat = True must be set
varnish.compat = True

# Connect to Varnish

# Purge Commands
varnish.purge(' ~ && req.url ~ ^/cached$')

# Run Stats
print varnish.stats()

# Quit and close the connection

More Usage:

from varnish_admin_socket import VarnishAdminSocket
# You may also set server, port, host, and secret on instantiation.
varnish = VarnishAdminSocket(host='',secret='123\n')
print varnish.stats()

# Setting auto_connect will automatically connect(), will run the first command (besides auth),
# and will then .quit()


Release History

This version
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
(4.0 kB) Copy SHA256 Hash SHA256
Source None Apr 21, 2011

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting