Skip to content

Commit 6909b3d

Browse files
authored
Update README.md (#47)
1 parent 27215a2 commit 6909b3d

File tree

1 file changed

+79
-64
lines changed

1 file changed

+79
-64
lines changed

README.md

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,134 @@
1-
# Open Bus Stride API
1+
# 🚌 Open Bus Stride API
22

3-
API For the [Open Bus Stride project](https://open-bus-map-search.hasadna.org.il/dashboard)
3+
**An API for the [Open Bus Stride Project](https://open-bus-map-search.hasadna.org.il/dashboard)**
44

5-
* Please report issues and feature requests [here](https://github.com/hasadna/open-bus/issues/new)
6-
* To get updates about the system status and for general help join Hasadna's Slack #open-bus channel ([Hasadna Slack signup link](https://join.slack.com/t/hasadna/shared_invite/zt-167h764cg-J18ZcY1odoitq978IyMMig))
5+
## 📢 Get Involved
76

8-
See [our contributing docs](https://github.com/hasadna/open-bus-pipelines/blob/main/CONTRIBUTING.md) if you want to suggest changes to this repository.
7+
- 💬 For general help and system updates, join the Hasadna Slack: [#open-bus channel](https://join.slack.com/t/hasadna/shared_invite/zt-167h764cg-J18ZcY1odoitq978IyMMig)
8+
- 🐞 Found a bug or have a feature request? [Open an issue](https://github.com/hasadna/open-bus-map-search/issues/new)
9+
- 🤝 Want to contribute? See our [contributing guidelines](https://github.com/hasadna/open-bus-pipelines/blob/main/CONTRIBUTING.md)
910

11+
## 🔗 Related Projects
1012

11-
## Tech Stack
13+
### Frontend
1214

13-
- [python](https://www.python.org/)
14-
- [fastAPI framework](https://fastapi.tiangolo.com/)
15-
- [postgresql](https://www.postgresql.org/)
15+
- [🗺️ Open Bus Map Search (Client App)](https://github.com/hasadna/open-bus-map-search) - [Live Website](https://open-bus-map-search.hasadna.org.il/dashboard)
16+
- [📦 Open Bus API Client (API Package Generator)](https://github.com/hasadna/open-bus-api-client) - [NPM Package](https://www.npmjs.com/package/@hasadna/open-bus-api-client)
1617

18+
### Backend
1719

18-
## Development using the Docker Compose environment
20+
- [🏗️ Open Bus Pipelines](https://github.com/hasadna/open-bus-pipelines)
21+
- [🌐 Open Bus Stride API (REST)](https://github.com/hasadna/open-bus-stride-api)[API Docs](https://open-bus-stride-api.hasadna.org.il/docs)
22+
- [🧾 Open Bus Stride DB](https://github.com/hasadna/open-bus-stride-db)
23+
- [🔧 Open Bus Stride ETL](https://github.com/hasadna/stride-etl)
24+
- [📚 Open Bus GTFS ETL](https://github.com/hasadna/gtfs-etl)
25+
- [📡 Open Bus SIRI Requester](https://github.com/hasadna/siri-requester)
26+
- [🧪 Open Bus SIRI ETL](https://github.com/hasadna/siri-etl)
1927

20-
This is the easiest option to start development, follow these instructions: https://github.com/hasadna/open-bus-pipelines/blob/main/README.md#stride-api
28+
## 🛠️ Tech Stack
2129

22-
For local development, see the additional functionality section: `Develop stride-api from a local clone`
30+
- [Python](https://www.python.org/)
31+
- [FastAPI](https://fastapi.tiangolo.com/)
32+
- [PostgreSQL](https://www.postgresql.org/)
2333

24-
## Local Development
34+
## 🚀 Getting Started
2535

26-
It's much easier to use the Docker Compose environment, but the following can be
27-
refferd to for more details regarding the internal processes and for development
28-
using your local Python interpreter.
36+
### Option 1: Using Docker Compose (Recommended)
2937

30-
### Install
38+
The easiest way to get up and running is with Docker Compose.
39+
Follow the instructions [here](https://github.com/hasadna/open-bus-pipelines/blob/main/README.md#stride-api).
3140

32-
Create a virtualenv (using Python 3.8)
41+
For local development (e.g. making changes to the code), also see:
42+
**`Develop stride-api from a local clone`** in the same document.
3343

34-
```
35-
python3.8 -m venv venv
36-
```
44+
### Option 2: Local Development (Manual Setup)
3745

38-
Update pip
46+
Use this if you prefer to run directly from your local Python environment.
3947

40-
```
41-
venv/bin/pip install --upgrade pip
42-
```
48+
#### 1. Clone and Setup
4349

44-
You should have a copy of open-bus-stride-db repository at ../open-bus-stride-db
50+
Ensure you have **Python 3.8** installed.
4551

46-
Install dependencies
52+
```bash
53+
python3.8 -m venv venv
54+
source venv/bin/activate # On Windows: venv\Scripts\activate
55+
pip install --upgrade pip
56+
pip install -r requirements-dev.txt
57+
```
58+
59+
Ensure a local clone of [open-bus-stride-db](https://github.com/hasadna/open-bus-stride-db) exists at:
4760

4861
```
49-
venv/bin/pip install -r requirements-dev.txt
62+
../open-bus-stride-db
5063
```
5164

52-
### Use
65+
#### 2. Database Connection
5366

54-
You need a DB to connect to, there are 2 options here:
67+
You’ll need a database. You have two options:
5568

56-
* Start the stride-db from open-bus-pipelines docker-compose environment
57-
* Connect to the production DB using the Redash read-only credentials
58-
* Create a `.env` file with the following, replacing the url to the production redash read-only url: `export SQLALCHEMY_URL=postgresql://postgres:123456@localhost`
59-
* Source the .env: `. .env`
69+
- **Option A**: Start `stride-db` using the Docker Compose environment from [open-bus-pipelines](https://github.com/hasadna/open-bus-pipelines).
70+
- **Option B**: Connect to the production DB using Redash read-only credentials.
6071

61-
Activate virtualenv
72+
Create a `.env` file:
6273

63-
```
64-
. venv/bin/activate
74+
```env
75+
export SQLALCHEMY_URL=postgresql://postgres:123456@localhost
6576
```
6677

67-
Start the FastAPI server with automatic reload on changes
78+
Then source it:
6879

80+
```bash
81+
. .env
6982
```
83+
84+
#### 3. Run the API Server
85+
86+
```bash
7087
uvicorn open_bus_stride_api.main:app --reload
7188
```
7289

73-
See the API docs at http://localhost:8000/docs
90+
Access the interactive API docs at:
91+
👉 [http://localhost:8000/docs](http://localhost:8000/docs)
7492

75-
### Manage APIs
93+
## 🧩 API Development
7694

77-
All existing APIs from the docs are defined under ```open_bus_stride_api/routers/<base_router_name>.py```
95+
All routes are defined in:
7896

79-
Follow this example to create or edit a simple API for a specific table with filters:
97+
```
98+
open_bus_stride_api/routers/<base_router_name>.py
99+
```
80100

101+
### ✍️ Example API
81102

82-
```
83-
@router.<http_method>("/<api_path>", tags=[<file_name>], response_model=<pydantic_response_model>) //
84-
def name(<filtering_params>, limit, offset): # always include limit & offest to allow easy iteration on the data
103+
```python
104+
@router.<http_method>("/<api_path>", tags=["<tag_name>"], response_model=<ResponseModel>)
105+
def name(<filtering_params>, limit, offset):
85106
return common.get_list(
86-
<db_model>, limit, offset,
87-
[
88-
{'type': <filter_type>, 'field': <db_stcruct>.<specific_id>, 'value': <filter_param>},
107+
<DBModel>, limit, offset,
108+
[
109+
{'type': <filter_type>, 'field': <DBModel>.<field>, 'value': <filter_param>},
89110
]
90111
)
91112
```
92113

93-
Filter types are defined at ```open_bus_stride_api/routers/common.py -> get_list_query_filter_<filter_type>``` (e.g.: 'equal', 'date_in_range')
114+
- **Filters**: Defined in `routers/common.py``get_list_query_filter_<filter_type>` (Examples: `'equal'`, `'date_in_range'`)
94115

95-
### Running Tests
116+
Always include `limit` and `offset` for pagination.
96117

97-
Install for local development as described above.
118+
## 🧪 Running Tests
98119

99-
Install test requirements:
120+
Set up your environment as described in the **Local Development** section above.
100121

101-
```
122+
Install test dependencies:
123+
124+
```bash
102125
pip install -r tests/requirements.txt
103126
```
104127

105-
To run the tests you need to connect to a DB with full stride data,
106-
easiest way is to connect to the production DB as described above by
107-
setting the SQLALCHEMY_URL env var accordingly.
128+
Ensure the DB contains full Stride data (production read-only access works).
108129

109-
Run all tests with full output, exiting on first error:
130+
Run tests:
110131

111-
```
132+
```bash
112133
pytest -svvx
113134
```
114-
115-
Pytest has many options, see the help message for details.
116-
117-
118-
### Link To The Client Repo
119-
- [client repo](https://github.com/hasadna/open-bus-map-search)

0 commit comments

Comments
 (0)