Skip to main content

allfactors

Python server-side SDK for AllFactors Analytics

Installation

pip install allfactors

or

uv add allfactors

Usage

Sync

from allfactors import AllFactors

# Initialize the SDK
af = AllFactors('your-domain', 'your-access-key', 'your-secret-key')

# Helper to read cookies (implementation varies by framework)
# FastAPI: request.cookies.get(name)
# Django:  request.COOKIES.get(name)
# Flask:   request.cookies.get(name)
# Sanic:   request.cookies.get(name)

# Send a signup event
try:
    result = af.send_signup(
        'user@example.com',
        'form',
        'app.yourcompany.com',
        '/registration/signup',
        request.cookies.get('af_usr'),
        request.cookies.get('af_ses')
    )
    print('Signup tracked successfully:', result)
except Exception as e:
    print('Error tracking signup:', e)

Async

from allfactors import AsyncAllFactors
import logging

# Initialize the SDK
af = AsyncAllFactors('your-domain', 'your-access-key', 'your-secret-key')
logger = logging.getLogger(__name__)

# Helper to read cookies (implementation varies by framework)
# FastAPI: request.cookies.get(name)
# Django:  request.COOKIES.get(name)
# Flask:   request.cookies.get(name)
# Sanic:   request.cookies.get(name)

# Send a signup event
async def user_signup(request):
    email = request.body.get('email')
    af_usr = request.cookies.get('af_usr')
    af_ses = request.cookies.get('af_ses')

    if af_usr and af_ses:
        try:
            result = await af.send_signup(
                email,
                'form',
                'app.yourcompany.com',
                request.url.path,
                af_usr,
                af_ses
            )
            logger.info('Signup tracked successfully:', result)
        except Exception as e:
            logger.error('Error tracking signup:', e)

    # the rest of your user sign-up code
    return JSONResponse({'success': True}, status_code=201)

With Proxy Configuration

from allfactors import AllFactors

af = AllFactors('your-domain', 'your-access-key', 'your-secret-key', {
    'proxy': {
        'host': 'proxy.example.com',
        'port': 8080,
        'protocol': 'http',
        'auth': {
            'username': 'proxy-user',
            'password': 'proxy-password'
        }
    }
})

# Use the SDK as normal
af.send_signup('user@example.com',
               'form',
               'app.example.com',
               '/path/of/user/signup/page',
               request.cookies.get('af_usr'),
               request.cookies.get('af_ses')
               )

API

Constructor

AllFactors(domain: str, access_key: str, secret_key: str, config: dict | None = None)
AsyncAllFactors(domain: str, access_key: str, secret_key: str, config: dict | None = None)

Parameters:

  • domain (str): Your AllFactors domain
  • access_key (str): Your AllFactors access key
  • secret_key (str): Your AllFactors secret key
  • config (optional dict): Configuration options
    • proxy (optional dict): Proxy server configuration
      • host (str): Proxy server hostname
      • port (int): Proxy server port
      • protocol (optional str): Proxy protocol ('http' or 'https')
      • auth (optional dict): Proxy authentication
        • username (str): Proxy username
        • password (str): Proxy password

Methods

send_signup(email, type, hostname, path, af_usr, af_ses)

Sends a signup event to AllFactors.

Parameters:

  • email (str): User email address
  • type (str): Signup type - either 'oauth' or 'form'
  • hostname (str): The hostname that the signup occured on
  • path (str): The path of the page that the signup occured on
  • af_usr (str): AllFactors user identifier (read from the af_usr HTTP cookie)
  • af_ses (str): AllFactors session identifier (read from the af_ses HTTP cookie)

Important: The af_usr and af_ses parameters should be read from HTTP cookies set by the AllFactors client-side tracking script. Do not generate random values for these parameters.

Returns: dict with the API response

Development

Building

uv build

License

MIT

Release files for allfactors 1.0.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 allfactors 1.0.2
File Size Uploaded
allfactors-1.0.2.tar.gz 6.7 kB Details

Built distribution (wheel)

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

Total release size: 17.4 kB

Release files / allfactors-1.0.2.tar.gz

Download URL allfactors-1.0.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cd91123c17bd6015fa75933068407f7a909be28325168eaf8927f4f6cac1aba5
BLAKE2b-256 checksum
How to use checksums
85fa890e57cb7a81eb79ab0813f5af046a5e9445358c029e51b2bb5952ddda7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / allfactors-1.0.2-py3-none-any.whl

Download URL allfactors-1.0.2-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23d77ab5de97234df46723e89a683a69051250b071aaad7bba4c30e6786247b4
BLAKE2b-256 checksum
How to use checksums
ea9d396a580ca158fd77e9f803578510589f376dfde0f657b10a364a2e47ffe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

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