Skip to main content

Generate auto proxy config files (PAC) from a declaration

Tests


This package aims to make it possible to create simple proxy scripts declaratively. It will never cover all the subtleties. If you have unusual requirements, it is better to write the proxy script directly in JavaScript

Usage

You can install the package with pip.

pip install paccreator

You can also load the script directly from github with pip.

pip install git+https://github.com/73h/paccreator.git@main#egg=paccreator

Create a file called myproxy.yaml and define your proxy rules in it like this.

description: A description of proxy script # (optional, default=pac file for my company)
version: The version of proxy script # (optional, default=0.1)
proxies:
  - route: DIRECT
    description: A description of proxy # (optional, default=use this proxy)
    tags: # (optional) Here you can add any comments you like, which you can use to filter later. However, there are also standard annotations.
      - default # (optional) This marks the proxy as default if no other condition applies. if no default proxy is available, the first one is used.
      - catch-plain-hostnames # (optional) This proxy applies if there is no domain name in the hostname (no dots). You should not annotate this on several proxies.
    targets:
      - example.com
      - foo.example.com
      - .example.net
      # You can also use a network mask, ip-addresses, hosts or strings
  - route: PROXY proxy1.example.com:80; DIRECT
    targets:
      - 10.0.0.0/8

Run this in python.

import os
from paccreator import PacCreator

p = PacCreator()
with open(os.path.join("myproxy.yaml"), "r") as f:
    p.load_from_yaml(f.read())
    print(p.output())

You can also use with contextmanager.

import os
from paccreator import load_from_yaml

with open(os.path.join("myproxy.yaml"), "r") as f:
    with load_from_yaml(f.read()) as p:
        print(p.output())

Examples

A simple Example for a random company

yaml file

description: Simple proxy
proxies:
  - description: use direct connection
    route: DIRECT
    targets:
      - 10.0.0.0/8
      - .my-company.com
  - description: use my proxy
    route: PROXY proxy.my-company.com:80
    tags:
      - default
    targets:
      - www.my-company.com
      - contact.my-company.com
  - description: use the special proxy
    route: PROXY proxy.my-company.com:8080
    targets:
      - datacenter.my-company.com

As a result, you can see that it has resolved the overlap between .my-company.com and, for example, contact.my-company.com by first evaluating the exact subdomains. The network mask 10.0.0.0/8 was placed at the end to avoid DNS queries when they are not necessary.

function FindProxyForURL(url, host) {
    /*
        Description: Simple proxy
        Version: 0.1
    */
    host = host.toLowerCase();
    if (
        localHostOrDomainIs(host, "www.my-company.com")
        || localHostOrDomainIs(host, "contact.my-company.com")
    ) {
        /* use my proxy */
        return "PROXY proxy.my-company.com:80";
    }
    if (
        localHostOrDomainIs(host, "datacenter.my-company.com")
    ) {
        /* use the special proxy */
        return "PROXY proxy.my-company.com:8080";
    }
    if (
        dnsDomainIs(host, ".my-company.com")
    ) {
        /* use direct connection */
        return "DIRECT";
    }
    if (
        isInNet(host, "10.0.0.0", "255.0.0.0")
    ) {
        /* use direct connection */
        return "DIRECT";
    }
    /* Default: use my proxy */
    return "PROXY proxy.my-company.com:80";
}

Unit Tests Example

You can see all the options supported so far in the test examples.

Metadata

Release files for paccreator 0.2.2

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

Source distribution (sdist)

Source distribution for paccreator 0.2.2
File Size Uploaded Provenance
paccreator-0.2.2.tar.gz 8.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 16.5 kB

Release files / paccreator-0.2.2.tar.gz

Download URL paccreator-0.2.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f97927b879936f8353c2ee573a9dca7eab7ad739cd11f095ecfb74b12e9ba625
BLAKE2b-256 checksum
How to use checksums
bc52cb2223eff562c31da361a4a7ce7072dba32cd6133f61fd0e0b1f0cc51f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.12

Release files / paccreator-0.2.2-py3-none-any.whl

Download URL paccreator-0.2.2-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0120cd7bf4868bdc7f543bbcb948cf3096aa54b02bdfbcf5a6542fa32ac6c24
BLAKE2b-256 checksum
How to use checksums
d3eebca1561fea0daf6c4623cddf16bdd19b8c5c06ab3acc477cdd36f7dd41ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.12

Security for paccreator 0.2.2

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