Skip to main content

Effortless application hosting using Cloudflare Tunnels.

Project description

Hostify - Host from Anywhere

Turn old PCs into production servers with one line of code.

Host applications from old PCs or home machines using Cloudflare Tunnels. No port forwarding, no dynamic DNS, just pure simplicity.

PyPI version Python License: MIT


๐Ÿš€ Quick Start

from hostify import Host

# Host your app in one line
Host(domain="app.example.com", port=3000).serve()

That's it! Your app is now live at https://app.example.com with automatic HTTPS.


๐Ÿ“ฆ Installation

pip install hostify

Requirements:

  • Python >= 3.9
  • Cloudflare account with a domain
  • Cloudflare API token (setup guide)

๐ŸŽฏ Features

  • โœ… One-line API - Simple and intuitive
  • โœ… Automatic HTTPS - Secure by default via Cloudflare
  • โœ… No Port Forwarding - Works behind NAT/firewalls
  • โœ… Cross-Platform - Windows, Linux, macOS
  • โœ… Static Files - Built-in HTTP server
  • โœ… Existing Servers - Works with Flask, Node, PHP, etc.
  • โœ… Auto-Cleanup - Graceful shutdown with Ctrl+C
  • โœ… Auto-Recovery - Restarts on connection issues

๐Ÿ–ฅ๏ธ CLI Usage

Hostify also provides a powerful command-line interface for quick hosting:

Installation

pip install hostify

Commands

Host a static site:

hostify static ./my-website mysite.example.com

Host an existing server:

hostify port 3000 app.example.com

Show version:

hostify version

Get help:

hostify --help

Environment Setup

Set your Cloudflare API token:

Windows (PowerShell):

$env:CLOUDFLARE_API_TOKEN="your_token_here"

Linux/macOS:

export CLOUDFLARE_API_TOKEN="your_token_here"

CLI Examples

Example 1: Host a static portfolio

hostify static ./portfolio portfolio.example.com

Example 2: Host a Flask app running on port 5000

# Terminal 1: Start Flask
python app.py

# Terminal 2: Host it
hostify port 5000 flask-app.example.com

Example 3: Host a React development server

# Terminal 1: Start React dev server (usually port 3000)
npm start

# Terminal 2: Host it
hostify port 3000 react-app.example.com

๐Ÿ’ก Use Cases

  1. Development - Share local dev server with team
  2. Demos - Show clients your work without deployment
  3. Old Hardware - Turn old PCs into production servers
  4. Home Labs - Host personal projects from home
  5. Testing - Test webhooks and integrations locally

๐Ÿ“– Usage Examples

Example 1: Host Static Files

from hostify import Host

# Serve static HTML/CSS/JS files
Host(
    domain="mysite.example.com",
    path="./public"
).serve()

Example 2: Host Flask App

from flask import Flask
from hostify import Host

app = Flask(__name__)

@app.route('/')
def home():
    return "<h1>Hello World!</h1>"

if __name__ == '__main__':
    # Start Flask in background
    import threading
    threading.Thread(target=lambda: app.run(port=5000)).start()
    
    # Host it with hostify
    Host(domain="flask.example.com", port=5000).serve()

Example 3: Host Existing Server

from hostify import Host

# Your Node.js/PHP/Python server is already running on port 3000
Host(domain="app.example.com", port=3000).serve()

Example 4: Custom API Token

from hostify import Host

Host(
    domain="app.example.com",
    port=8000,
    api_token="your_cloudflare_api_token"
).serve()

๐Ÿ”ง Setup Guide

Step 1: Install Hostify

pip install hostify

Step 2: Get Cloudflare API Token

  1. Go to Cloudflare API Tokens
  2. Click "Create Token"
  3. Use "Edit Cloudflare Zero Trust" template or create custom token with:
    • Account โ†’ Cloudflare Tunnel โ†’ Edit
    • Zone โ†’ DNS โ†’ Edit
    • Zone โ†’ Zone โ†’ Read
  4. Copy the token

Detailed guide: CLOUDFLARE_SETUP.md

Step 3: Set Environment Variable

Windows (PowerShell):

$env:CF_API_TOKEN="your_token_here"

Linux/Mac:

export CF_API_TOKEN="your_token_here"

Permanent (add to profile):

# Linux/Mac: Add to ~/.bashrc or ~/.zshrc
echo 'export CF_API_TOKEN="your_token_here"' >> ~/.bashrc

# Windows: Use System Environment Variables
setx CF_API_TOKEN "your_token_here"

Step 4: Add Domain to Cloudflare

Make sure your domain is added to Cloudflare and nameservers are configured.

Step 5: Run Hostify

from hostify import Host

Host(domain="app.yourdomain.com", port=3000).serve()

๐ŸŽจ Live Demos

Check out these live examples hosted with hostify:

[!TIP] The demo site features a stunning futuristic design with neon effects, glassmorphism, and smooth animations. Check out THEME_UPDATE.md for details on the enhanced UI.


๐Ÿ“˜ Documentation

Comprehensive documentation is now available!


๐Ÿ“š API Reference

Host Class

Host(
    domain: str,           # Required: Full domain (e.g., "app.example.com")
    port: int = None,      # Port of existing server (mutually exclusive with path)
    path: str = None,      # Path to static files (mutually exclusive with port)
    api_token: str = None  # Optional: Cloudflare API token
)

Methods:

  • .serve() - Start hosting (blocks until Ctrl+C)

Parameters:

  • domain (required): Full domain or subdomain (e.g., "app.example.com")
  • port (optional): Port number where your app is running (1-65535)
  • path (optional): Path to directory with static files
  • api_token (optional): Cloudflare API token (defaults to CF_API_TOKEN env var)

Note: You must specify either port OR path, not both.


๐Ÿ” How It Works

  1. Creates Cloudflare Tunnel - Establishes secure connection
  2. Configures DNS - Automatically creates CNAME record
  3. Routes Traffic - Configures tunnel to route domain to your local server
  4. Manages Binary - Downloads and runs cloudflared automatically
  5. Monitors Connection - Auto-restarts on failures
  6. Cleans Up - Removes all resources on Ctrl+C

๐Ÿ› ๏ธ Troubleshooting

"No server found on port X"

Solution: Make sure your application is running before starting hostify.

# Terminal 1: Start your app
python app.py

# Terminal 2: Host it
python host.py

"Zone not found for domain"

Solution: Ensure your domain is added to Cloudflare and nameservers are configured.

"No Cloudflare accounts found"

Solution: Check your API token has the correct permissions:

  • Account โ†’ Cloudflare Tunnel โ†’ Edit
  • Zone โ†’ DNS โ†’ Edit
  • Zone โ†’ Zone โ†’ Read

Site shows 404

Solution: Wait 30-60 seconds for tunnel to fully connect and DNS to propagate.

"Cloudflare API token not found"

Solution: Set the CF_API_TOKEN environment variable or pass api_token parameter.


๐Ÿงช Testing

Run the comprehensive test suite:

python tests/test_suite.py

Expected output:

Results: 9/9 tests passed (100%)
All tests passed! Library is ready for publication.

๐Ÿ“ Project Structure

hostify/
โ”œโ”€โ”€ hostify/              # Main package
โ”‚   โ”œโ”€โ”€ __init__.py      # Package exports
โ”‚   โ”œโ”€โ”€ cloudflare.py    # Cloudflare API wrapper
โ”‚   โ”œโ”€โ”€ cloudflared.py   # Binary manager
โ”‚   โ”œโ”€โ”€ host.py          # Main Host class
โ”‚   โ””โ”€โ”€ utils.py         # Utilities
โ”œโ”€โ”€ examples/            # Usage examples
โ”œโ”€โ”€ tests/               # Test suite
โ””โ”€โ”€ docs/                # Documentation

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Built on Cloudflare Tunnels
  • Inspired by the need for simple, accessible hosting solutions

๐Ÿ“ž Support


๐Ÿ”ฎ Roadmap

  • Multiple domain support
  • Web dashboard for management
  • Authentication system
  • Custom cloudflared configuration
  • Load balancing
  • Health checks and monitoring
  • CLI tool

Made with โค๏ธ for developers who want to host from anywhere

Created by Yuvraj Arora

Uses Cloudflare Tunnel & Cloudflare APIs


โญ Star History

If you find this project useful, please consider giving it a star on GitHub!

Star History Chart

Project details


Download files

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

Source Distribution

hostify-0.2.1.tar.gz (69.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hostify-0.2.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file hostify-0.2.1.tar.gz.

File metadata

  • Download URL: hostify-0.2.1.tar.gz
  • Upload date:
  • Size: 69.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hostify-0.2.1.tar.gz
Algorithm Hash digest
SHA256 198f9c989883290f848dc0517e849863c17d7c35b8c13d8b0a9aec2843875dcc
MD5 504856b7c27f4a48ad93e066c78c44b2
BLAKE2b-256 68167dbfedd13fdb359fade788765aad437be892d0b6b20120dc78b556f59f72

See more details on using hashes here.

File details

Details for the file hostify-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: hostify-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hostify-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cad671dd29c9d38c70db72df27473af611261467368ff140445a038cc0cdec38
MD5 8f9947290b6db21fb23055b7f08d6c00
BLAKE2b-256 da620a62a983a4c16c3646ee2e1a87f94d0c4071a997444e18b5bc655e80bc6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page