Skip to main content

A Flask-based GIS backend package

Project description

GIS Flask

A Flask-based GIS backend package with JWT authentication, role-based permissions, interactive maps, health monitoring, and API documentation.

API Documentation

Features

  • JWT Authentication: Secure authentication using JSON Web Tokens (JWT) for API access control
  • Role-Based Access Control: Comprehensive permissions system for secure user access management
  • Interactive Maps: Integration with Folium for interactive map visualizations
  • API Documentation: Automatic Swagger/OpenAPI documentation
  • PostgreSQL Database: Robust data storage with UUID primary keys
  • Health Monitoring: Built-in health check endpoint
  • Modular Architecture: Well-organized codebase with clear separation of concerns

Getting Started

Prerequisites

  • Python 3.7+
  • PostgreSQL database
  • Required Python packages (see installation)

Installation Options

Option 1: Install as a Python Package

  1. Install directly from GitHub (or PyPI once published):

    pip install git+https://github.com/KimutaiLawrence/gisflask.git
    
  2. Set up environment variables:

    # Database connection
    export DATABASE_URL=postgresql://username:password@localhost:5432/gisflask
    
    # JWT secret
    export JWT_SECRET_KEY=your-secret-key
    
    # Session secret
    export SESSION_SECRET=your-session-secret
    
  3. Initialize the database and create admin user:

    # Initialize the database with default roles and permissions
    gisflask init-db
    
    # Create an admin user (defaults to admin/admin123 if not specified)
    gisflask create-admin --username admin --email admin@example.com --password admin123
    
  4. Run the application:

    gisflask run
    

Option 2: Clone and Run Directly

  1. Clone the repository:

    git clone https://github.com/KimutaiLawrence/gisflask.git
    cd gisflask
    
  2. Create a virtual environment:

    python -m venv venv
    venv\Scripts\activate  # On Windows: or other: source venv/bin/activate
    
  3. Install dependencies (choose one method):

    # Method 1: Install using requirements.txt
    pip install -r requirements.txt
    
    # Method 2: Install in development mode (recommended for development)
    pip install -e .
    
  4. Set up environment variables:

    # Database connection
    export DATABASE_URL=postgresql://username:password@localhost:5432/gisflask
    
    # JWT secret
    export JWT_SECRET_KEY=your-secret-key
    
    # Session secret
    export SESSION_SECRET=your-session-secret
    
  5. Initialize the database:

    # Using Flask-Migrate
    flask db init
    flask db migrate -m "Initial migration"
    flask db upgrade
    
    # OR using CLI commands
    gisflask init-db
    gisflask create-admin
    
  6. Run the application:

    python run.py
    # OR
    gisflask run --debug
    

The application will be available at http://localhost:5000.

Project Structure

app/
├── auth/               # Authentication related modules
│   ├── routes.py       # Auth endpoints (register, login, etc.)
│   ├── schemas.py      # Data validation schemas
│   └── utils.py        # Auth helper functions
├── main/               # Main application modules
│   ├── routes.py       # Main routes including map endpoints
│   └── schemas.py      # Data validation schemas
├── users/              # User management (placeholder)
│   └── routes.py       # User CRUD operations
├── products/           # Product management (placeholder) 
│   └── routes.py       # Product CRUD operations
├── services/           # Service modules
│   └── email.py        # Email service
├── templates/          # HTML templates
│   └── ...            
├── __init__.py         # Application factory
├── config.py           # Configuration settings
├── extensions.py       # Flask extensions
├── models.py           # Database models
└── utils.py            # Utility functions

Key Components

Authentication System

The application uses JWT-based authentication:

  • Registration: Create a new user account
  • Login: Authenticate and receive access/refresh tokens
  • Token Refresh: Get a new access token using refresh token
  • Protected Routes: Access control using JWT authentication

Default admin credentials:

  • Username: admin
  • Password: admin123

Role-Based Access Control

The application implements a flexible permission system:

  • Roles: Admin, User, etc.
  • Permissions: Fine-grained control over actions
  • Access Control Decorators: @jwt_required(), @admin_required

Map Visualization

Interactive maps using Folium:

  • View maps at /map
  • Customize center coordinates and zoom level
  • Save map preferences per user

API Documentation

Swagger/OpenAPI documentation is available at /docs/.

API Documentation

The API documentation provides:

  • Interactive testing of all endpoints
  • Detailed request/response schemas
  • Authentication requirements
  • Example requests and responses

Functional Endpoints

These endpoints are fully implemented and can be tested immediately from a frontend application:

  • Authentication: /auth/register, /auth/login, /auth/refresh, /auth/protected
  • Map Services: /map, /api/map/preferences
  • Health Check: /health

Placeholder Endpoints

The following modules contain placeholder endpoints that need to be uncommented in their respective route files to work:

  • Users Module: All endpoints under /users/*
  • Products Module: All endpoints under /products/*

To activate these endpoints:

  1. Open the corresponding route files (app/users/routes.py, app/products/routes.py)
  2. Uncomment the example code sections
  3. Implement any additional functionality you need

Extending the Application

The application includes placeholder modules for adding custom functionality:

  • Users Module: Example of user management functionality
  • Products Module: Example of product management functionality

Each module includes placeholder templates and commented example code to help you understand how to implement your own features.

License

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

Creating Your Own Package

This project is designed to be used as a template for your own GIS-enabled backend. Here's how to create your own package based on this template:

  1. Fork or clone this repository

    git clone https://github.com/KimutaiLawrence/gisflask.git 
    cd gisflask
    
  2. Customize the package details

    Edit the setup.py file to change:

    • package name
    • version
    • author information
    • description
    • repository URL
    • other metadata
  3. Customize the application

    • Add your own models to app/models.py
    • Create new blueprint modules for your features
    • Customize templates and views
    • Add additional services as needed
  4. Build and publish your package

    # Build the package
    python -m build
    
    # Install locally for testing
    pip install -e .
    
    # Publish to PyPI (once ready)
    python -m twine upload dist/*
    

Customization Guide

Adding New Models

  1. Edit app/models.py to add your new model class:

    class YourModel(db.Model):
        __tablename__ = "your_models"
        
        id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
        name = db.Column(db.String(100), nullable=False)
        # Add more fields as needed
    
  2. Create migrations:

    flask db migrate -m "Add YourModel"
    flask db upgrade
    

Creating a New Module

  1. Create a new directory structure:

    mkdir -p app/your_module
    touch app/your_module/__init__.py
    touch app/your_module/routes.py
    
  2. Define your blueprint in __init__.py:

    from flask import Blueprint
    your_module_bp = Blueprint('your_module', __name__, url_prefix='/your-module')
    from app.your_module import routes
    
  3. Register the blueprint in app/__init__.py:

    from app.your_module import your_module_bp
    app.register_blueprint(your_module_bp)
    
  4. Create templates for your module:

    mkdir -p app/templates/your_module
    
  5. Implement your routes and views in routes.py

Deployment

For production deployment, consider:

  1. Using a proper WSGI server like Gunicorn or uWSGI
  2. Setting up a reverse proxy with Nginx
  3. Configuring proper environment variables for production
  4. Setting up database backups and monitoring

Acknowledgments

  • Flask and its extensions
  • Folium for interactive maps
  • Swagger/OpenAPI for API documentation

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

gisflask-0.1.2.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

gisflask-0.1.2-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file gisflask-0.1.2.tar.gz.

File metadata

  • Download URL: gisflask-0.1.2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gisflask-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f057b6aaa54aa58067965ee8632cf5818a256fd8d6995403cd8e59ada0b3bab6
MD5 ea0b67ac3f8aa3fbd207c2c768dcbc15
BLAKE2b-256 20d028b344cd0240e29629ee0b6e412b0701268fb224a147fdfb25c975661562

See more details on using hashes here.

Provenance

The following attestation bundles were made for gisflask-0.1.2.tar.gz:

Publisher: python-package.yml on KimutaiLawrence/gisflask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gisflask-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gisflask-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gisflask-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 47ce1d0e449cf606c3d1d0abe34cb4b5a41cc31323cb199b227f968ef1460310
MD5 636e67d5929b954a63e39c4bda9c3565
BLAKE2b-256 a41836c0623f0f44427820bc0ee2f90b825f95d84de79bd8ba59d97ea537a8f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for gisflask-0.1.2-py3-none-any.whl:

Publisher: python-package.yml on KimutaiLawrence/gisflask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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