API used for a ETL system from CSV files to a SQL database, and execute specific queries against the database.
Built with SQLAlchemy, FastAPI, pandas and PostgreSQL. ruff was used for linting and formatting.
- Python 3.11 and
pipenvmust be installed in your system. - PostgreSQL 14.9 must be installed in your system. There must be a database called
company.
- Clone the repository
- Run
pipenv install
- To create the tables used for the project, run
psql -d company -a -f database/queries/create_tables.sql - Rename
.env.exampleto.envand modify the variables to your connection data. - To run the API in developer mode type
pipenv run dev-apiin your terminal. For production environmentspipenv run apishould be used. This will give you auvicornweb server atlocalhost:8000.OpenAPIdocs can be seen atlocalhost:8000/docs.
Used to upload CSV files to the database. Endpoint parameters are as it follows:
file: Must be a.csvfiletable: One ofjob,departmentoremployee. Schema for these tables can be seen inmodels.pystart_row: Integer between 1-1000, signals the start of the file that will be read.end_row: Integer between 1-1000, signals the number of rows that will be read.- If one of
start_rowandend_roware not present, the file will be read in its entirety.
Shows the result of the query hirings_by_q.sql. Response is formatted as it follows:
[
{'department': 'Accounting', 'job': 'Account Representative IV', 'q1': 1, 'q2': 0, 'q3': 0, 'q4': 0},
{'department': 'Accounting', 'job': 'Actuary', 'q1': 0, 'q2': 1, 'q3': 0, 'q4': 0},
{'department': 'Accounting', 'job': 'Analyst Programmer', 'q1': 0, 'q2': 0, 'q3': 1, 'q4': 0},
{'department': 'Accounting', 'job': 'Budget/Accounting Analyst III', 'q1': 0, 'q2': 1, 'q3': 0, 'q4': 0},
...
Shows the result of the query higher_than_avg.sql. Response is formatted as it follows:
[
{'id': 8, 'department': 'Support', 'hired': 221},
{'id': 5, 'department': 'Engineering', 'hired': 208}
...
This project is released under the MIT License.