A command-line application that extracts GitLab project information via the GitLab API and stores it in a database.
- Connect to GitLab API using Python
- Store project data in a SQL database using -SQLAlchemy
- Perform CRUD operations on project data
- Implement proper error handling and logging
- Use OpenAPI-generated clients for API communication
- Store API credentials securely
- Python 3.8+
- SQLAlchemy
- Requests
- Python-dotenv
- PyJWT
- Cryptography
- Pydantic
- Clone this repository: git clone cd gitlab-api-project
- Create and activate a virtual environment: python -m venv venv venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies: pip install -r requirements.txt
- Configure environment variables: cp .env.example .env Edit .env with your GitLab API token and other settings
- GITLAB_API_URL=https://gitlab.com/api/v4
- GITLAB_API_TOKEN=your_private_token
- DATABASE_URI=sqlite:///gitlab_data.db
- LOG_LEVEL=INFO
- Fetching Projects python app.py fetch
- Managing Projects
python app.py list
python app.py show PROJECT_ID
python app.py update PROJECT_ID
python app.py delete PROJECT_ID
python app.py -h
The application uses SQLite with the following schema:
Projects Table
- id: Integer, Primary Key
- name: String, Not Null
- description: Text
- created_at: DateTime
- updated_at: DateTime
- web_url: String
- visibility: String Namespaces Table
- id: Integer, Primary Key
- name: String, Not Null
- path: String, Not Null
- project_id: Integer, Foreign Key to Projects
npm install @openapitools/openapi-generator-cli -g openapi-generator-cli generate -i https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/openapi/openapi.yaml -g python -o ./api/generated
The application implements comprehensive logging with:
- Configurable log levels
- File and console logging
- Log rotation with timestamps
- Structured log format
- API tokens stored in environment variables
- Parameterized database queries
- Input validation
- Secure error handling
- Connection pooling with validation
SQLAlchemy==1.4.49 requests==2.31.0 python-dotenv==1.0.0 urllib3==2.0.7 PyJWT==2.8.0 cryptography==41.0.5 pydantic==2.5.2