Skip to main content

AllFactors Python server-side SDK

Project description

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

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

allfactors-1.0.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

allfactors-1.0.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file allfactors-1.0.2.tar.gz.

File metadata

  • Download URL: allfactors-1.0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for allfactors-1.0.2.tar.gz
Algorithm Hash digest
SHA256 cd91123c17bd6015fa75933068407f7a909be28325168eaf8927f4f6cac1aba5
MD5 3b69bb476abf8ed3216a1654f86b6c8d
BLAKE2b-256 85fa890e57cb7a81eb79ab0813f5af046a5e9445358c029e51b2bb5952ddda7d

See more details on using hashes here.

File details

Details for the file allfactors-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: allfactors-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for allfactors-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23d77ab5de97234df46723e89a683a69051250b071aaad7bba4c30e6786247b4
MD5 56cea36e6ff04edc863239fcc5308106
BLAKE2b-256 ea9d396a580ca158fd77e9f803578510589f376dfde0f657b10a364a2e47ffe1

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