Skip to content

Commit

Permalink
Add async support (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Jorim Tielemans <tielemans.jorim@gmail.com>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent 0a36922 commit 65135bf
Show file tree
Hide file tree
Showing 5 changed files with 1,018 additions and 244 deletions.
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# pyRail

A Python wrapper for the iRail API, designed to make interacting with iRail simple and efficient.
An async Python wrapper for the iRail API, designed to make interacting with iRail simple and efficient.
Built with aiohttp, it provides non-blocking I/O operations for optimal performance in async applications.

## Overview
pyRail is a Python library that provides a convenient interface for interacting with the iRail API. It supports various endpoints such as stations, liveboard, vehicle, connections, and disturbances. The library includes features like caching and rate limiting to optimize API usage.

## Features
- Async handling
- Retrieve real-time train information, including liveboards and vehicle details.
- Access train station data, connections, and disturbances.
- Supports API endpoints: stations, liveboard, vehicle, connections, and disturbances.
Expand All @@ -20,19 +22,36 @@ pip install pyrail
```

## Usage
Here is an example of how to use pyRail:
Here is an example of how to use pyRail (async):

```python
from pyrail.irail import iRail

# Create an instance of the iRail class
api = iRail(format='json', lang='en')

# Make a request to the 'stations' endpoint
stations = api.get_stations()

# Print the response
print(stations)
async with iRail(format='json', lang='en') as api:
try:
# Get all stations
stations = await api.get_stations()
print("Stations:", stations)

# Get connections between stations
connections = await api.get_connections(
from_station='Antwerpen-Centraal',
to_station='Brussel-Centraal'
)
print("Connections:", connections)
except Exception as e:
print(f"Error occurred: {e}")

# Example of concurrent requests with asyncio.gather
async with iRail() as api:
stations, connections = await asyncio.gather(
api.get_stations(),
api.get_connections(
from_station='Antwerpen-Centraal',
to_station='Brussel-Centraal'
)
)
```

## Configuration
Expand All @@ -50,14 +69,12 @@ api = iRail(format='json', lang='en')
```bash
git clone https://github.com/tjorim/pyrail.git
```
2. Install dependencies using Poetry:
```bash
poetry install
```
3. Run tests:
2. Open the project in a devcontainer:
```bash
poetry run pytest
cd pyrail
code .
```
Make sure you have the Remote - Containers extension installed in VS Code. The devcontainer setup includes all necessary dependencies and tools for development.

## Logging
You can set the logging level at runtime to get detailed logs:
Expand All @@ -74,6 +91,7 @@ Contributions are welcome! Please open an issue or submit a pull request.
## Contributors
- @tjorim
- @jcoetsie
- @lgnap

## License
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Loading

0 comments on commit 65135bf

Please sign in to comment.