Skip to main content

BallotAPI Server

WARNING: THE CODE FOR THIS README HASN'T BEEN WRITTEN YET

This folder has the code for the BallotAPI server itself. If you want to run your own mirror of our ballot API, this is the code you are looking for.

Installation

1. Install the BallotAPI server

The easiest way to install is via PyPI:

pip install ballotapi

To update, just add the -U flag.

pip install -U ballotapi

Alternatively, you can install directly from source:

git clone https://github.com/open-austin/ballotapi.git
pip install -e ballotapi/

Alternatively, you can run from source directly:

git clone https://github.com/open-austin/ballotapi.git
cd ballotapi
pip install -r requirements.txt
python3 -m ballotapi.cli --help

2. Setup your database

The BallotAPI server requires a database of ballot data be loaded. You can download a copy of various test databases, the full production database, or build your own.

You can skip this step if you already have your database loaded.

# Install PostgreSQL and PostGIS plugin
sudo apt-get install postgresql postgis

# Create a BallotAPI database and user
sudo -u postgres psql -c "CREATE DATABASE ballotapi;"
sudo -u postgres psql -c "CREATE USER ballotapiuser WITH ENCRYPTED PASSWORD 'yourpasswordhere';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ballotapi TO ballotapiuser;"

# Set database connection uri environmental variable
export BALLOTAPI_DB_URI="postgresql://ballotapiuser:yourpasswordhere@localhost:5432/ballotapi"

# Load a dataset into your database
ballotapi load "testdata-default"

Usage

Now that the BallotAPI server is installed and a database is loaded, you are ready to run the server!

ballotapi runserver

To customize the settings of your server, check out which options there are using ballotapi runserver --help.

usage: ballotapi runserver [-h] [--db-uri URI] [--cache-uri URI] [--host HOST]
                           [--port PORT] [--uwsgi-ini FILE] [--daemon]

optional arguments:
  -h, --help        show this help message and exit
  --db-uri URI      connection uri to the postgres database (default is
                    BALLOTAPI_DB_URI env variable)
  --cache-uri URI   connection uri to a cache server (default is None)
  --host HOST       listen for this host (default localhost)
  --port PORT       listen on this port (default 1776)
  --uwsgi-ini FILE  settings for uwsgi (default is a simple http server)
  --daemon          detach server to run in background as a daemon (optional)

To stop the server when you're running it directly from the command line, simply use Ctrl+C. To stop/reload a server that's running in the background as a daemon, send signals to the process.

# gracefully reload
killall -s SIGHUP ballotapi

# gracefully stop
killall -s SIGTERM ballotapi

# brutally reload
killall -s SIGINT ballotapi

# brutally stop
killall -s SIGKILL ballotapi

Commands

usage: ballotapi [-h] <subcommand> ...

Documentation: https://ballotapi.org/docs

optional arguments:
  -h, --help    show this help message and exit

available subcommands:
  <subcommand>
    runserver   Run the web server
    load        Load in a database from a source location
    export      Dump the database as a sql file

Contributing

Help us out! If you find a bug or want to improving this codebase, feel free to submit an issue or pull request. Check out our CONTRIBUTING docs for more details.

Metadata

Release files for ballotapi 0.0.1

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

Source distribution (sdist)

Source distribution for ballotapi 0.0.1
File Size Uploaded
ballotapi-0.0.1.tar.gz 246.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ballotapi 0.0.1
File Interpreter ABI Platform
ballotapi-0.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 254.6 kB

Release files / ballotapi-0.0.1.tar.gz

Download URL ballotapi-0.0.1.tar.gz
Size 246.8 kB
Tags Source
SHA-256 checksum
How to use checksums
037074d83e360af119e440ffd43600f38aaa8e9efdad559356eade2386db74fc
BLAKE2b-256 checksum
How to use checksums
60f319cedeb7c2b93f28cd310f7e3ffaf9360d7f8cee0a3c38d28847372a170c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.12

Release files / ballotapi-0.0.1-py2.py3-none-any.whl

Download URL ballotapi-0.0.1-py2.py3-none-any.whl
Size 7.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
830f70027cb428970e2002308bc75b895910216bb4baaf86844e26e167d90908
BLAKE2b-256 checksum
How to use checksums
3496e42eb15a5da1b786ad9d8703e7d2921db71982e9f235b9e72d94cabcdeba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.12

Release history Release notifications | RSS feed

This release

0.0.1 This release

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