parkapi-sources


Nameparkapi-sources JSON
Version 0.14.2 PyPI version JSON
download
home_pageNone
SummaryParkAPI Sources is a collection of converters from several different data sources to normalized ParkAPI data.
upload_time2024-11-12 18:35:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords data parking converter mobility car bike
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ParkAPI Sources

ParkAPI Sources is a collection of converters from several different data sources to normalized ParkAPI data. ParkAPI does support parking
for cars, for bikes and lockers. The data model is based on the original ParkAPI project and tries to stay compatible to DATEX II Parking
Publication Light at any extension of the model.

We support following data sources:

| name                                                                              | purpose | type        | uid                      | realtime |
|-----------------------------------------------------------------------------------|---------|-------------|--------------------------|----------|
| APCOA Services                                                                    | car     | pull        | `apcoa`                  | no       |
| Deutsche Bahn                                                                     | car     | pull        | `bahn_v2`                | no       |
| Stadt Bietigheim-Bissingen                                                        | car     | pull        | `bietigheim_bissingen`   | yes      |
| Barrierefreie Reisekette Baden-Württemberg: PKW-Parkplätze                        | car     | pull        | `bfrk_bw_car`            | no       |
| Barrierefreie Reisekette Baden-Württemberg: Fahrrad-Parkplätze                    | bike    | pull        | `bfrk_bw_bike`           | no       |
| Stadt Ellwangen                                                                   | car     | push (xlsx) | `ellwangen`              | no       |
| Stadt Buchen                                                                      | car     | push (json) | `buchen`                 | yes      |
| Stadt Freiburg                                                                    | car     | pull        | `freiburg`               | yes      |
| GOLDBECK Parking Services                                                         | car     | push (xlsx) | `goldbeck`               | no       |
| Stadt Heidelberg                                                                  | car     | pull        | `heidelberg`             | yes      |
| Stadt Herrenberg                                                                  | car     | pull        | `herrenberg`             | no       |
| Stadt Herrenberg - Munigrid                                                       | bike    | pull        | `herrenberg_bike`        | no       |
| PARK SERVICE HÜFNER GmbH + Co. KG                                                 | car     | push (xlsx) | `huefner`                | no       |
| Stadt Karlsruhe: PKW-Parkplätze                                                   | car     | pull        | `karlsruhe`              | yes      |
| Stadt Karlsruhe: Fahhrrad-Abstellangen                                            | bike    | pull        | `karlsruhe_bike`         | no       |
| Kienzler: Bike and Ride                                                           | bike    | pull        | `kienzler_bike_and_ride` | yes      |
| Kienzler: Karlsruhe                                                               | bike    | pull        | `kienzler_karlruhe`      | yes      |
| Kienzler: Neckarsulm                                                              | bike    | pull        | `kienzler_neckarsulm`    | yes      |
| Kienzler: Offenburg                                                               | bike    | pull        | `kienzler_offenburg`     | yes      |
| Kienzler: RadSafe                                                                 | bike    | pull        | `kienzler_rad_safe`      | yes      |
| Kienzler: Stuttgart                                                               | bike    | pull        | `kienzler_stuttgart`     | yes      |
| Kienzler: VRN                                                                     | bike    | pull        | `kienzler_vrn`           | yes      |
| Konstanz                                                                          | car     | pull        | `konstanz`               | yes      |
| Stadt Konstanz: Fahrrad-Abstellanlagen                                            | bike    | push        | `konstanz_bike`          | no       |
| Stadt Mannheim                                                                    | car     | push (json) | `mannheim`               | yes      |
| Stadt Neckarsulm: PKW-Parkplätze                                                  | car     | pull        | `neckarsulm`             | no       |
| Stadt Neckarsulm: Fahrrad-Abstellanlagen                                          | bike    | pull        | `neckarsulm_bike`        | no       |
| Open-Data-Plattform öV Schweiz                                                    | car     | pull (json) | `opendata_swiss`         | no       |
| P + M Baden-Württemberg                                                           | car     | pull        | `p_m_bw`                 | yes      |
| Baden-Württemberg: Parken und Mitfahren                                           | car     | push (xlsx) | `pum_bw`                 | no       |
| RadVIS Baden-Württemberg (experimental)                                           | bike    | pull        | `radvis_bw`              | no       |
| Parkraumgesellschaft Baden-Württemberg                                            | car     | pull        | `pbw`                    | yes      |
| Stadt Pforzheim                                                                   | car     | push (csv)  | `pforzheim`              | no       |
| Stadt Reutlingen: PKW-Parkplätze                                                  | car     | push (csv)  | `reutlingen`             | no       |
| Stadt Reutlingen: Fahrrad-Abstellanlagen                                          | bike    | push (csv)  | `reutlingen_bike`        | no       |
| Stadt Stuttgart                                                                   | car     | push (json) | `stuttgart`              | yes      |
| Stadt Ulm                                                                         | car     | pull        | `ulm`                    | yes      |
| Verband Region Stuttgart: Bondorf                                                 | car     | pull        | `vrs_bondorf`            | yes      |
| Verband Region Stuttgart: Kirchheim                                               | car     | pull        | `vrs_kirchheim`          | yes      |
| Verband Region Stuttgart: Neustadt                                                | car     | pull        | `vrs_neustadt`           | yes      |
| Verband Region Stuttgart: Park and Ride                                           | car     | push (xlsx) | `vrs_p_r`                | no       |
| Verband Region Stuttgart: Vaihingen                                               | car     | pull        | `vrs_vaihingen`          | yes      |

New converters for new sources are always welcome, please have a look at "Contribute" below.


## Install

ParkAPI Sources is a python module published at [PyPI](https://pypi.org/project/parkapi-sources/). Therefore, you can install it by

```shell
pip install parkapi-sources
```

If you use parkapi-sources in a project, we recommend to fix the version. As long as parkapi-sources is beta, breaking changes might be
introduced on minor version level (like: change from 0.1.1 to 0.2.0). As soon as 1.0 is released, we will follow
[Semantic Versioning](https://semver.org), which means that breaking changes will just appear on major version changes (like: change from 1.1.2 to 2.0.0).
You can expect a lot of changes in the minor version level, as any new converter is a new feature.


## Usage

Your starting point is always the `ParkAPISources` where all Sources are registered.

```python
from parkapi_sources import ParkAPISources

my_sources = ParkAPISources()
```

`ParkAPISources` accepts following parameters:

- `config: Optional[dict] = None` is a dictionary for config values, especially secrets.
- `converter_uids: Optional[list[str]] = None` is used for loading just the converter uids you want to load
- `no_pull_converter: bool = False` is used for limiting converters to pull converters
- `no_push_converter: bool = False` is used for limiting converters to push converters


### Configuration

Config values are mostly individual for specific converters: if there are required config values, they are defined at the converter
definition right at the top:

```
required_config_keys = ['MY_SECRET']
```

`ParkAPISources` offers a method to check if all config values are set:

```python
from parkapi_sources import ParkAPISources

my_sources = ParkAPISources()
my_sources.check_credentials()
```

If not all config values are set, a `MissingConfigException` is thrown. It's recommended to run this check after initializing the module
to prevent exceptions during runtime.

Besides converter-individual config values, there are two global values which can be used to configure the source of GeoJSON files. Per
default, static GeoJSON files are fetched from this repository. This behaviour can be changed:

- `STATIC_GEOJSON_BASE_URL` defines another base URL for GeoJSON files
- `STATIC_GEOJSON_BASE_PATH` defines a lokal path instead, so the application will load files locally without network requests


### Use converters

After initializing, you will find all initialized converters at `ParkAPISources.converter_by_uid`. As the input is very different, so are
the methods you have to use. In general, you can differ between two major strategies:


### Pull converters

Pull converters are responsible for getting data from an external data source. This can be an REST endpoints as well as HTML which is
scraped. Pull converters always split up in static and realtime data, because at most sources, this is not the same. Each pull converter
has two methods:

1) `get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:`
2) `def get_realtime_parking_sites(self) -> tuple[list[RealtimeParkingSiteInput], list[ImportParkingSiteException]]:`


### Push converters

Push converters are responsible to handle data which is pushed to the service using defined endpoints. Usually, these converters are used
as a handler behind HTTP endpoints, but of course you can use them in other ways, too, for example command line scripts.

Push converters always handle specific formats, therefore, there are multiple types of push converters. All push converters return a
`tuple[list[StaticParkingSiteInput | RealtimeParkingSiteInput], list[ImportParkingSiteException]]`, therefore they decided based on the
given data if it's static or realtime data they got - or even both, then each dataset ends up in two entries in the first list.

1) A `CsvConverter` handles CSV files: `handle_csv_string(self, data: StringIO)`
2) A `JsonConverter` handles JSON based data: `handle_json(self, data: dict | list)`
3) A `XlsxConverter` handles XMLX data: `def handle_xlsx(self, workbook: Workbook)` parsed by `openpyxl`
4) A `XmlConverter` handles XML data: `def handle_xml(self, root: Element)` parsed by `lxml`


### Results

At `webapp/models/parking_site_inputs.py`, you can find the definition of `StaticParkingSiteInput` and `RealtimeParkingSiteInput`. These
`dataclasses` are also [`validataclasses`](https://pypi.org/project/validataclass/), so you can be sure that the data you get is validated.


## Contribute

We are happy about any contributions. We do not expect that yoy can develop Python, but of course things might speed up if


### Report bugs

As ParkAPI-Sources integrates a lot of external data sources, sometimes without a proper definition, converters might run into issues
because of changes on the data source side. If you see that happening, please add a bug report at the
[issues](https://github.com/ParkenDD/parkapi-sources-v3/issues). If possible, please add the data which fails.


### Contribute new source data

If you see a nice data source which is not covered by ParkAPI-sources, you can always create a feature request at our
[issues](https://github.com/ParkenDD/parkapi-sources-v3/issues). If you do so, please add the data you found, so we can actually build
the converter. If possible, please try to find out a licence, too.


### Write a new Converters

We always welcome merge requests with new converters. A merge request should contain the following:

* MIT licenced code
* A converter which validates the input in a way that the output follows the data model
* A test with example data to ensure that the converter works with current data


## Write a new converter

First you have to determine which type of converter you need. If you get the data from an endpoint, you will need a `PushConverter`, if
you have a file you want to push via HTTP or CLI, you need a `PullConverter`.


### Write the converter

In order to write a converter, you need a directory at `converters`. Please name your directory in a way that it points to the actual
converter you will write. If it's just one converter, the `uid` is usually the best approach.

At `converters/your-converter`, you will at least need a `converter.py` and an `__init__.py`. In most cases, you will also need some
`validataclasses` you can put in `models.py`. Validation is crucial in this library, because the users of this library should not think
invalid data. Additionally, if you have very specific new data types, you can write new `validataclass` validators you can usually put in
`validators.py`.


### Testing the converter

In order to proof that the validator works, we need to test the basic functionality. In order to do this, we need a snapshot of the data
which should be integrated. Common place for this data is `tests/converters/data/filename-starting-with-uid.ending`. This data should be
used in one or multiple tests (in several cases two tests, one for static, one for realtime data) stored at `tests/converters/uid_test.py`.

If you test a `PullConverter`, you will need no mock requests. This can be done using the fantastic
[`requests_mock`](https://pypi.org/project/requests-mock/) library.

If you created new validators, these should be tested with different inputs. Usually, `pytest.parametrize` is a nice approach to do this.


### Migrate a converter

If you want to migrate a v1 or v2 converter, you can re-use some of the code. There is a paradigm change, though: `parkapi-source-v3`
enforces a strict validation after transforming the data, while v1 and v2 converters don't. ParkAPI v1 / v2 converters are always pull
converters, so the base class is always `PullConverter`.

Instead of defining `POOL`, you will set `source_info` at the same place. Attributes are almost the same, except for `id` was renamed to
`uid`, and there is the new attribute `has_realtime_data`, which has to be set.

ParkAPI v1 and v2 used two methods for static and realtime data, just as `parkapi-sources-v3`:

- the old static data handling `def get_lot_infos(self) -> List[LotInfo]:` is
  `get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:` in `parkapi-sources-v3`.
- the old realtime data handling`def get_lot_data(self) -> List[LotData]:` is
  `def get_realtime_parking_sites(self) -> tuple[list[RealtimeParkingSiteInput], list[ImportParkingSiteException]]:` in
  `parkapi-sources-v3`.

The result objects have quite the same idea, too:

- `LotInfo` gets `StaticParkingSiteInput`
- `LotData` gets `RealtimeParkingSiteInput`

There's also a helper for scraped content: before, there was `self.request_soup(self.POOL.public_url)` in order to get a `BeautifulSoup`
element. Now, there is a helper mixin called `PullScraperMixin`. You can use it this way:

```
class MyPullConverter(PullConverter, PullScraperMixin):
```

Additionally, there is another mixin for the GeoJSON files you already know from v1 and v2 converters: `StaticGeojsonDataMixin`. Using this,
you can just define the static data method this way:

```
    def get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:
        return self._get_static_parking_site_inputs_and_exceptions(source_uid=self.source_info.uid)
```

The default location for GeoJSON files is a [separate repository](https://github.com/ParkenDD/parkapi-static-data).

Please keep in mind that you will have to add tests for the migrated scraper.


### Linting

As we try to keep a consistent code style, please lint your code before creating the merge request. We use `ruff` for linting and
formatting. There is Makefile target to do both: `make lint`. It runs the following commands:

```bash
ruff format ./src ./tests
ruff check --fix ./src ./tests
```

If you don't have `ruff` installed globally, you can create a virtual environment for these tools:

```bash
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt

ruff format ./src ./tests
ruff check --fix ./src ./tests
```


### Make your new converter available

All available converters should be registered at the `ParkAPISources` class in order to make them accessible for users of this library, so
please register your converter there. The new converter should also be added to the table in this README.md file.


### Release process

If you created a merge request, the maintainers will review your code. If everything is fine, it will be merged to `main`, and a new
release will be created soon. As written above, we follow SemVer, so any new converter will add plus one to the minor version. In order to
use this new release, please keep in mind to update your `requirements.txt` / update the dependency manager you use.


## Licence

This library is under MIT licence. Please look at `LICENCE.txt` for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "parkapi-sources",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "\"Ernesto Ruge, binary butterfly GmbH\" <ernesto.ruge@binary-butterfly.de>",
    "keywords": "data, parking, converter, mobility, car, bike",
    "author": null,
    "author_email": "\"Ernesto Ruge, binary butterfly GmbH\" <ernesto.ruge@binary-butterfly.de>",
    "download_url": "https://files.pythonhosted.org/packages/53/2c/f6ef418d40b66a66f59a2b9837361bf35803fd20b23c8e912035e5ba674d/parkapi_sources-0.14.2.tar.gz",
    "platform": null,
    "description": "# ParkAPI Sources\n\nParkAPI Sources is a collection of converters from several different data sources to normalized ParkAPI data. ParkAPI does support parking\nfor cars, for bikes and lockers. The data model is based on the original ParkAPI project and tries to stay compatible to DATEX II Parking\nPublication Light at any extension of the model.\n\nWe support following data sources:\n\n| name                                                                              | purpose | type        | uid                      | realtime |\n|-----------------------------------------------------------------------------------|---------|-------------|--------------------------|----------|\n| APCOA Services                                                                    | car     | pull        | `apcoa`                  | no       |\n| Deutsche Bahn                                                                     | car     | pull        | `bahn_v2`                | no       |\n| Stadt Bietigheim-Bissingen                                                        | car     | pull        | `bietigheim_bissingen`   | yes      |\n| Barrierefreie Reisekette Baden-W\u00fcrttemberg: PKW-Parkpl\u00e4tze                        | car     | pull        | `bfrk_bw_car`            | no       |\n| Barrierefreie Reisekette Baden-W\u00fcrttemberg: Fahrrad-Parkpl\u00e4tze                    | bike    | pull        | `bfrk_bw_bike`           | no       |\n| Stadt Ellwangen                                                                   | car     | push (xlsx) | `ellwangen`              | no       |\n| Stadt Buchen                                                                      | car     | push (json) | `buchen`                 | yes      |\n| Stadt Freiburg                                                                    | car     | pull        | `freiburg`               | yes      |\n| GOLDBECK Parking Services                                                         | car     | push (xlsx) | `goldbeck`               | no       |\n| Stadt Heidelberg                                                                  | car     | pull        | `heidelberg`             | yes      |\n| Stadt Herrenberg                                                                  | car     | pull        | `herrenberg`             | no       |\n| Stadt Herrenberg - Munigrid                                                       | bike    | pull        | `herrenberg_bike`        | no       |\n| PARK SERVICE H\u00dcFNER GmbH + Co. KG                                                 | car     | push (xlsx) | `huefner`                | no       |\n| Stadt Karlsruhe: PKW-Parkpl\u00e4tze                                                   | car     | pull        | `karlsruhe`              | yes      |\n| Stadt Karlsruhe: Fahhrrad-Abstellangen                                            | bike    | pull        | `karlsruhe_bike`         | no       |\n| Kienzler: Bike and Ride                                                           | bike    | pull        | `kienzler_bike_and_ride` | yes      |\n| Kienzler: Karlsruhe                                                               | bike    | pull        | `kienzler_karlruhe`      | yes      |\n| Kienzler: Neckarsulm                                                              | bike    | pull        | `kienzler_neckarsulm`    | yes      |\n| Kienzler: Offenburg                                                               | bike    | pull        | `kienzler_offenburg`     | yes      |\n| Kienzler: RadSafe                                                                 | bike    | pull        | `kienzler_rad_safe`      | yes      |\n| Kienzler: Stuttgart                                                               | bike    | pull        | `kienzler_stuttgart`     | yes      |\n| Kienzler: VRN                                                                     | bike    | pull        | `kienzler_vrn`           | yes      |\n| Konstanz                                                                          | car     | pull        | `konstanz`               | yes      |\n| Stadt Konstanz: Fahrrad-Abstellanlagen                                            | bike    | push        | `konstanz_bike`          | no       |\n| Stadt Mannheim                                                                    | car     | push (json) | `mannheim`               | yes      |\n| Stadt Neckarsulm: PKW-Parkpl\u00e4tze                                                  | car     | pull        | `neckarsulm`             | no       |\n| Stadt Neckarsulm: Fahrrad-Abstellanlagen                                          | bike    | pull        | `neckarsulm_bike`        | no       |\n| Open-Data-Plattform \u00f6V Schweiz                                                    | car     | pull (json) | `opendata_swiss`         | no       |\n| P + M Baden-W\u00fcrttemberg                                                           | car     | pull        | `p_m_bw`                 | yes      |\n| Baden-W\u00fcrttemberg: Parken und Mitfahren                                           | car     | push (xlsx) | `pum_bw`                 | no       |\n| RadVIS Baden-W\u00fcrttemberg (experimental)                                           | bike    | pull        | `radvis_bw`              | no       |\n| Parkraumgesellschaft Baden-W\u00fcrttemberg                                            | car     | pull        | `pbw`                    | yes      |\n| Stadt Pforzheim                                                                   | car     | push (csv)  | `pforzheim`              | no       |\n| Stadt Reutlingen: PKW-Parkpl\u00e4tze                                                  | car     | push (csv)  | `reutlingen`             | no       |\n| Stadt Reutlingen: Fahrrad-Abstellanlagen                                          | bike    | push (csv)  | `reutlingen_bike`        | no       |\n| Stadt Stuttgart                                                                   | car     | push (json) | `stuttgart`              | yes      |\n| Stadt Ulm                                                                         | car     | pull        | `ulm`                    | yes      |\n| Verband Region Stuttgart: Bondorf                                                 | car     | pull        | `vrs_bondorf`            | yes      |\n| Verband Region Stuttgart: Kirchheim                                               | car     | pull        | `vrs_kirchheim`          | yes      |\n| Verband Region Stuttgart: Neustadt                                                | car     | pull        | `vrs_neustadt`           | yes      |\n| Verband Region Stuttgart: Park and Ride                                           | car     | push (xlsx) | `vrs_p_r`                | no       |\n| Verband Region Stuttgart: Vaihingen                                               | car     | pull        | `vrs_vaihingen`          | yes      |\n\nNew converters for new sources are always welcome, please have a look at \"Contribute\" below.\n\n\n## Install\n\nParkAPI Sources is a python module published at [PyPI](https://pypi.org/project/parkapi-sources/). Therefore, you can install it by\n\n```shell\npip install parkapi-sources\n```\n\nIf you use parkapi-sources in a project, we recommend to fix the version. As long as parkapi-sources is beta, breaking changes might be\nintroduced on minor version level (like: change from 0.1.1 to 0.2.0). As soon as 1.0 is released, we will follow\n[Semantic Versioning](https://semver.org), which means that breaking changes will just appear on major version changes (like: change from 1.1.2 to 2.0.0).\nYou can expect a lot of changes in the minor version level, as any new converter is a new feature.\n\n\n## Usage\n\nYour starting point is always the `ParkAPISources` where all Sources are registered.\n\n```python\nfrom parkapi_sources import ParkAPISources\n\nmy_sources = ParkAPISources()\n```\n\n`ParkAPISources` accepts following parameters:\n\n- `config: Optional[dict] = None` is a dictionary for config values, especially secrets.\n- `converter_uids: Optional[list[str]] = None` is used for loading just the converter uids you want to load\n- `no_pull_converter: bool = False` is used for limiting converters to pull converters\n- `no_push_converter: bool = False` is used for limiting converters to push converters\n\n\n### Configuration\n\nConfig values are mostly individual for specific converters: if there are required config values, they are defined at the converter\ndefinition right at the top:\n\n```\nrequired_config_keys = ['MY_SECRET']\n```\n\n`ParkAPISources` offers a method to check if all config values are set:\n\n```python\nfrom parkapi_sources import ParkAPISources\n\nmy_sources = ParkAPISources()\nmy_sources.check_credentials()\n```\n\nIf not all config values are set, a `MissingConfigException` is thrown. It's recommended to run this check after initializing the module\nto prevent exceptions during runtime.\n\nBesides converter-individual config values, there are two global values which can be used to configure the source of GeoJSON files. Per\ndefault, static GeoJSON files are fetched from this repository. This behaviour can be changed:\n\n- `STATIC_GEOJSON_BASE_URL` defines another base URL for GeoJSON files\n- `STATIC_GEOJSON_BASE_PATH` defines a lokal path instead, so the application will load files locally without network requests\n\n\n### Use converters\n\nAfter initializing, you will find all initialized converters at `ParkAPISources.converter_by_uid`. As the input is very different, so are\nthe methods you have to use. In general, you can differ between two major strategies:\n\n\n### Pull converters\n\nPull converters are responsible for getting data from an external data source. This can be an REST endpoints as well as HTML which is\nscraped. Pull converters always split up in static and realtime data, because at most sources, this is not the same. Each pull converter\nhas two methods:\n\n1) `get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:`\n2) `def get_realtime_parking_sites(self) -> tuple[list[RealtimeParkingSiteInput], list[ImportParkingSiteException]]:`\n\n\n### Push converters\n\nPush converters are responsible to handle data which is pushed to the service using defined endpoints. Usually, these converters are used\nas a handler behind HTTP endpoints, but of course you can use them in other ways, too, for example command line scripts.\n\nPush converters always handle specific formats, therefore, there are multiple types of push converters. All push converters return a\n`tuple[list[StaticParkingSiteInput | RealtimeParkingSiteInput], list[ImportParkingSiteException]]`, therefore they decided based on the\ngiven data if it's static or realtime data they got - or even both, then each dataset ends up in two entries in the first list.\n\n1) A `CsvConverter` handles CSV files: `handle_csv_string(self, data: StringIO)`\n2) A `JsonConverter` handles JSON based data: `handle_json(self, data: dict | list)`\n3) A `XlsxConverter` handles XMLX data: `def handle_xlsx(self, workbook: Workbook)` parsed by `openpyxl`\n4) A `XmlConverter` handles XML data: `def handle_xml(self, root: Element)` parsed by `lxml`\n\n\n### Results\n\nAt `webapp/models/parking_site_inputs.py`, you can find the definition of `StaticParkingSiteInput` and `RealtimeParkingSiteInput`. These\n`dataclasses` are also [`validataclasses`](https://pypi.org/project/validataclass/), so you can be sure that the data you get is validated.\n\n\n## Contribute\n\nWe are happy about any contributions. We do not expect that yoy can develop Python, but of course things might speed up if\n\n\n### Report bugs\n\nAs ParkAPI-Sources integrates a lot of external data sources, sometimes without a proper definition, converters might run into issues\nbecause of changes on the data source side. If you see that happening, please add a bug report at the\n[issues](https://github.com/ParkenDD/parkapi-sources-v3/issues). If possible, please add the data which fails.\n\n\n### Contribute new source data\n\nIf you see a nice data source which is not covered by ParkAPI-sources, you can always create a feature request at our\n[issues](https://github.com/ParkenDD/parkapi-sources-v3/issues). If you do so, please add the data you found, so we can actually build\nthe converter. If possible, please try to find out a licence, too.\n\n\n### Write a new Converters\n\nWe always welcome merge requests with new converters. A merge request should contain the following:\n\n* MIT licenced code\n* A converter which validates the input in a way that the output follows the data model\n* A test with example data to ensure that the converter works with current data\n\n\n## Write a new converter\n\nFirst you have to determine which type of converter you need. If you get the data from an endpoint, you will need a `PushConverter`, if\nyou have a file you want to push via HTTP or CLI, you need a `PullConverter`.\n\n\n### Write the converter\n\nIn order to write a converter, you need a directory at `converters`. Please name your directory in a way that it points to the actual\nconverter you will write. If it's just one converter, the `uid` is usually the best approach.\n\nAt `converters/your-converter`, you will at least need a `converter.py` and an `__init__.py`. In most cases, you will also need some\n`validataclasses` you can put in `models.py`. Validation is crucial in this library, because the users of this library should not think\ninvalid data. Additionally, if you have very specific new data types, you can write new `validataclass` validators you can usually put in\n`validators.py`.\n\n\n### Testing the converter\n\nIn order to proof that the validator works, we need to test the basic functionality. In order to do this, we need a snapshot of the data\nwhich should be integrated. Common place for this data is `tests/converters/data/filename-starting-with-uid.ending`. This data should be\nused in one or multiple tests (in several cases two tests, one for static, one for realtime data) stored at `tests/converters/uid_test.py`.\n\nIf you test a `PullConverter`, you will need no mock requests. This can be done using the fantastic\n[`requests_mock`](https://pypi.org/project/requests-mock/) library.\n\nIf you created new validators, these should be tested with different inputs. Usually, `pytest.parametrize` is a nice approach to do this.\n\n\n### Migrate a converter\n\nIf you want to migrate a v1 or v2 converter, you can re-use some of the code. There is a paradigm change, though: `parkapi-source-v3`\nenforces a strict validation after transforming the data, while v1 and v2 converters don't. ParkAPI v1 / v2 converters are always pull\nconverters, so the base class is always `PullConverter`.\n\nInstead of defining `POOL`, you will set `source_info` at the same place. Attributes are almost the same, except for `id` was renamed to\n`uid`, and there is the new attribute `has_realtime_data`, which has to be set.\n\nParkAPI v1 and v2 used two methods for static and realtime data, just as `parkapi-sources-v3`:\n\n- the old static data handling `def get_lot_infos(self) -> List[LotInfo]:` is\n  `get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:` in `parkapi-sources-v3`.\n- the old realtime data handling`def get_lot_data(self) -> List[LotData]:` is\n  `def get_realtime_parking_sites(self) -> tuple[list[RealtimeParkingSiteInput], list[ImportParkingSiteException]]:` in\n  `parkapi-sources-v3`.\n\nThe result objects have quite the same idea, too:\n\n- `LotInfo` gets `StaticParkingSiteInput`\n- `LotData` gets `RealtimeParkingSiteInput`\n\nThere's also a helper for scraped content: before, there was `self.request_soup(self.POOL.public_url)` in order to get a `BeautifulSoup`\nelement. Now, there is a helper mixin called `PullScraperMixin`. You can use it this way:\n\n```\nclass MyPullConverter(PullConverter, PullScraperMixin):\n```\n\nAdditionally, there is another mixin for the GeoJSON files you already know from v1 and v2 converters: `StaticGeojsonDataMixin`. Using this,\nyou can just define the static data method this way:\n\n```\n    def get_static_parking_sites(self) -> tuple[list[StaticParkingSiteInput], list[ImportParkingSiteException]]:\n        return self._get_static_parking_site_inputs_and_exceptions(source_uid=self.source_info.uid)\n```\n\nThe default location for GeoJSON files is a [separate repository](https://github.com/ParkenDD/parkapi-static-data).\n\nPlease keep in mind that you will have to add tests for the migrated scraper.\n\n\n### Linting\n\nAs we try to keep a consistent code style, please lint your code before creating the merge request. We use `ruff` for linting and\nformatting. There is Makefile target to do both: `make lint`. It runs the following commands:\n\n```bash\nruff format ./src ./tests\nruff check --fix ./src ./tests\n```\n\nIf you don't have `ruff` installed globally, you can create a virtual environment for these tools:\n\n```bash\nvirtualenv venv\nsource venv/bin/activate\npip install -r requirements.txt -r requirements-dev.txt\n\nruff format ./src ./tests\nruff check --fix ./src ./tests\n```\n\n\n### Make your new converter available\n\nAll available converters should be registered at the `ParkAPISources` class in order to make them accessible for users of this library, so\nplease register your converter there. The new converter should also be added to the table in this README.md file.\n\n\n### Release process\n\nIf you created a merge request, the maintainers will review your code. If everything is fine, it will be merged to `main`, and a new\nrelease will be created soon. As written above, we follow SemVer, so any new converter will add plus one to the minor version. In order to\nuse this new release, please keep in mind to update your `requirements.txt` / update the dependency manager you use.\n\n\n## Licence\n\nThis library is under MIT licence. Please look at `LICENCE.txt` for details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "ParkAPI Sources is a collection of converters from several different data sources to normalized ParkAPI data.",
    "version": "0.14.2",
    "project_urls": null,
    "split_keywords": [
        "data",
        " parking",
        " converter",
        " mobility",
        " car",
        " bike"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96d52e87ea0636b02bb8d0cfa5e8fc99a95df55b168ea3f2e9806014fcde3736",
                "md5": "750b1e4d1ae1349fcf18f28596c977cd",
                "sha256": "f3013a0a0ab3f93c6fabbd8a88d5fde1621989334ccff2c8ed556810a2269b16"
            },
            "downloads": -1,
            "filename": "parkapi_sources-0.14.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "750b1e4d1ae1349fcf18f28596c977cd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 139055,
            "upload_time": "2024-11-12T18:35:36",
            "upload_time_iso_8601": "2024-11-12T18:35:36.460539Z",
            "url": "https://files.pythonhosted.org/packages/96/d5/2e87ea0636b02bb8d0cfa5e8fc99a95df55b168ea3f2e9806014fcde3736/parkapi_sources-0.14.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "532cf6ef418d40b66a66f59a2b9837361bf35803fd20b23c8e912035e5ba674d",
                "md5": "8c7e4b6701f54f2bb94d2fd35aaefc54",
                "sha256": "9a6fa61ac17246ddf351e1223dc23662c5ab75a81a8181537fc5a963ee366e32"
            },
            "downloads": -1,
            "filename": "parkapi_sources-0.14.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8c7e4b6701f54f2bb94d2fd35aaefc54",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 1548490,
            "upload_time": "2024-11-12T18:35:38",
            "upload_time_iso_8601": "2024-11-12T18:35:38.406473Z",
            "url": "https://files.pythonhosted.org/packages/53/2c/f6ef418d40b66a66f59a2b9837361bf35803fd20b23c8e912035e5ba674d/parkapi_sources-0.14.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-12 18:35:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "parkapi-sources"
}
        
Elapsed time: 1.37979s