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.
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
-
Install directly from GitHub (or PyPI once published):
pip install git+https://github.com/KimutaiLawrence/gisflask.git
-
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
-
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
-
Run the application:
gisflask run
Option 2: Clone and Run Directly
-
Clone the repository:
git clone https://github.com/KimutaiLawrence/gisflask.git cd gisflask
-
Create a virtual environment:
python -m venv venv venv\Scripts\activate # On Windows: or other: source venv/bin/activate
-
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 .
-
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
-
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
-
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/.
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:
- Open the corresponding route files (
app/users/routes.py,app/products/routes.py) - Uncomment the example code sections
- 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:
-
Fork or clone this repository
git clone https://github.com/KimutaiLawrence/gisflask.git cd gisflask
-
Customize the package details
Edit the
setup.pyfile to change:- package name
- version
- author information
- description
- repository URL
- other metadata
-
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
- Add your own models to
-
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
-
Edit
app/models.pyto 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
-
Create migrations:
flask db migrate -m "Add YourModel" flask db upgrade
Creating a New Module
-
Create a new directory structure:
mkdir -p app/your_module touch app/your_module/__init__.py touch app/your_module/routes.py
-
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
-
Register the blueprint in
app/__init__.py:from app.your_module import your_module_bp app.register_blueprint(your_module_bp)
-
Create templates for your module:
mkdir -p app/templates/your_module
-
Implement your routes and views in
routes.py
Deployment
For production deployment, consider:
- Using a proper WSGI server like Gunicorn or uWSGI
- Setting up a reverse proxy with Nginx
- Configuring proper environment variables for production
- Setting up database backups and monitoring
Acknowledgments
- Flask and its extensions
- Folium for interactive maps
- Swagger/OpenAPI for API documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f057b6aaa54aa58067965ee8632cf5818a256fd8d6995403cd8e59ada0b3bab6
|
|
| MD5 |
ea0b67ac3f8aa3fbd207c2c768dcbc15
|
|
| BLAKE2b-256 |
20d028b344cd0240e29629ee0b6e412b0701268fb224a147fdfb25c975661562
|
Provenance
The following attestation bundles were made for gisflask-0.1.2.tar.gz:
Publisher:
python-package.yml on KimutaiLawrence/gisflask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gisflask-0.1.2.tar.gz -
Subject digest:
f057b6aaa54aa58067965ee8632cf5818a256fd8d6995403cd8e59ada0b3bab6 - Sigstore transparency entry: 217517399
- Sigstore integration time:
-
Permalink:
KimutaiLawrence/gisflask@010e98062a3b1f0ef6ba670848287f9b09d39a30 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/KimutaiLawrence
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@010e98062a3b1f0ef6ba670848287f9b09d39a30 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ce1d0e449cf606c3d1d0abe34cb4b5a41cc31323cb199b227f968ef1460310
|
|
| MD5 |
636e67d5929b954a63e39c4bda9c3565
|
|
| BLAKE2b-256 |
a41836c0623f0f44427820bc0ee2f90b825f95d84de79bd8ba59d97ea537a8f1
|
Provenance
The following attestation bundles were made for gisflask-0.1.2-py3-none-any.whl:
Publisher:
python-package.yml on KimutaiLawrence/gisflask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gisflask-0.1.2-py3-none-any.whl -
Subject digest:
47ce1d0e449cf606c3d1d0abe34cb4b5a41cc31323cb199b227f968ef1460310 - Sigstore transparency entry: 217517404
- Sigstore integration time:
-
Permalink:
KimutaiLawrence/gisflask@010e98062a3b1f0ef6ba670848287f9b09d39a30 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/KimutaiLawrence
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@010e98062a3b1f0ef6ba670848287f9b09d39a30 -
Trigger Event:
push
-
Statement type: