A Python client for the FOGIS API (Svensk Fotboll)
Project description
fogis_api_client
A Python client for interacting with the FOGIS API (Svensk Fotboll).
Features
- Authentication with FOGIS API.
- Lazy login - automatically authenticates when needed.
- Fetching match lists, team players, officials, and events.
- Reporting match events and results.
- Error handling and logging.
Installation
pip install fogis-api-client-timmyBird
Usage
import logging
from fogis_api_client.fogis_api_client import FogisApiClient, FogisLoginError, FogisAPIRequestError
logging.basicConfig(level=logging.INFO)
username = "your_fogis_username"
password = "your_fogis_password"
try:
client = FogisApiClient(username, password)
# No need to call login() explicitly - the client implements lazy login
matches = client.fetch_matches_list_json()
if matches:
print(f"Found {len(matches)} matches.")
else:
print("No matches found.")
except FogisLoginError as e:
print(f"Login failed: {e}")
except FogisAPIRequestError as e:
print(f"API request error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
You can also call login() explicitly if you want to pre-authenticate:
client = FogisApiClient(username, password)
client.login() # Explicitly authenticate
# ... make API requests
Docker Support
The package includes Docker support for easy deployment and development:
Production Deployment
-
Create a
.envfile with your credentials:FOGIS_USERNAME=your_fogis_username FOGIS_PASSWORD=your_fogis_password -
Start the service:
docker compose up -d
-
Access the API at http://localhost:8080
Development Environment
For development, we provide a more comprehensive setup:
-
Start the development environment:
./dev.sh
-
Run integration tests:
./run_integration_tests.sh
For more details on the development environment, see README.dev.md.
API Endpoints
The HTTP API wrapper provides the following endpoints:
Basic Endpoints
GET /- Returns a test JSON responseGET /hello- Returns a simple hello world message
Match Endpoints
GET /matches- Returns a list of matchesPOST /matches/filter- Returns a filtered list of matches based on provided criteriaGET /match/<match_id>- Returns details for a specific matchGET /match/<match_id>/result- Returns result information for a specific matchGET /match/<match_id>/officials- Returns officials information for a specific matchPOST /match/<match_id>/finish- Marks a match report as completed/finished
Match Events Endpoints
GET /match/<match_id>/events- Returns events for a specific matchPOST /match/<match_id>/events- Reports a new event for a matchPOST /match/<match_id>/events/clear- Clears all events for a match
Team Endpoints
GET /team/<team_id>/players- Returns player information for a specific teamGET /team/<team_id>/officials- Returns officials information for a specific team
Query Parameters
Many endpoints support query parameters for filtering, sorting, and pagination:
/matches Endpoint
from_date- Start date for filtering matches (format: YYYY-MM-DD)to_date- End date for filtering matches (format: YYYY-MM-DD)limit- Maximum number of matches to returnoffset- Number of matches to skip (for pagination)sort_by- Field to sort by (options: datum, hemmalag, bortalag, tavling)order- Sort order, 'asc' or 'desc'
/match/<match_id> Endpoint
include_events- Whether to include events in the response (default: true)include_players- Whether to include players in the response (default: false)include_officials- Whether to include officials in the response (default: false)
/match/<match_id>/events Endpoint
type- Filter events by type (e.g., 'goal', 'card', 'substitution')player- Filter events by player nameteam- Filter events by team namelimit- Maximum number of events to returnoffset- Number of events to skip (for pagination)sort_by- Field to sort by (options: time, type, player, team)order- Sort order, 'asc' or 'desc'
/team/<team_id>/players Endpoint
name- Filter players by nameposition- Filter players by positionnumber- Filter players by jersey numberlimit- Maximum number of players to returnoffset- Number of players to skip (for pagination)sort_by- Field to sort by (options: name, position, number)order- Sort order, 'asc' or 'desc'
/team/<team_id>/officials Endpoint
name- Filter officials by namerole- Filter officials by rolelimit- Maximum number of officials to returnoffset- Number of officials to skip (for pagination)sort_by- Field to sort by (options: name, role)order- Sort order, 'asc' or 'desc'
Filter Parameters for /matches/filter Endpoint
The /matches/filter endpoint accepts the following parameters in the request body (JSON):
from_date- Start date for filtering matches (format: YYYY-MM-DD)to_date- End date for filtering matches (format: YYYY-MM-DD)status- Match status (e.g., "upcoming", "completed")age_category- Age category for filtering matchesgender- Gender for filtering matchesfootball_type- Type of football (e.g., "indoor", "outdoor")
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes
- Run the pre-merge check to ensure all tests pass:
./pre-merge-check.sh
- Commit your changes:
git commit -m "Add your feature" - Push to the branch:
git push origin feature/your-feature-name - Create a pull request
Pre-Merge Check
Before merging any changes, always run the pre-merge check script to ensure all tests pass:
./pre-merge-check.sh
This script:
- Runs all unit tests
- Builds and tests the Docker image (if Docker is available)
- Ensures your changes won't break existing functionality
Error Handling
The package includes custom exceptions for common API errors:
FogisLoginError: Raised when login fails.
FogisAPIRequestError: Raised for general API request errors.
License
MIT License
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 fogis_api_client_timmybird-0.0.10.tar.gz.
File metadata
- Download URL: fogis_api_client_timmybird-0.0.10.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42cf2eb4c53af1b9f02b5b21176c87d587c7f1f2c10c3875ea900f1135991ce5
|
|
| MD5 |
51a73ff25a39260f20bed369a7a5aeeb
|
|
| BLAKE2b-256 |
84d3512d582d609304d061f8089963a14a0c397b92b265900cfb88c26aba89d8
|
File details
Details for the file fogis_api_client_timmybird-0.0.10-py3-none-any.whl.
File metadata
- Download URL: fogis_api_client_timmybird-0.0.10-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f7010c865e8411d8ce30ed09fc2a59e57bb50842cd036d960fd4db9c97fd8c
|
|
| MD5 |
ed57f2ff42aee702e5fdb86f31f1ee04
|
|
| BLAKE2b-256 |
3de67a4667e1bdc22f91f4aa33c921043d71c27cf225feade46d80062b66d3a3
|