kleinanzeigen-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kleinanzeigen_api-0.1.0/.gitignore +28 -0
- kleinanzeigen_api-0.1.0/LICENSE +21 -0
- kleinanzeigen_api-0.1.0/PKG-INFO +214 -0
- kleinanzeigen_api-0.1.0/README.md +187 -0
- kleinanzeigen_api-0.1.0/pyproject.toml +59 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/__init__.py +25 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/__main__.py +4 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/categories.py +157 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/cli.py +120 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/client.py +418 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/data/categories.json +956 -0
- kleinanzeigen_api-0.1.0/src/kleinanzeigen_api/py.typed +0 -0
- kleinanzeigen_api-0.1.0/tests/test_categories.py +93 -0
- kleinanzeigen_api-0.1.0/tests/test_cli.py +33 -0
- kleinanzeigen_api-0.1.0/tests/test_parsing.py +96 -0
- kleinanzeigen_api-0.1.0/tests/test_search.py +102 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
wheelhouse/
|
|
9
|
+
|
|
10
|
+
# Virtualenvs
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
# Tooling caches
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
.mypy_cache/
|
|
18
|
+
.ruff_cache/
|
|
19
|
+
.tox/
|
|
20
|
+
|
|
21
|
+
# OS / editor
|
|
22
|
+
.DS_Store
|
|
23
|
+
.idea/
|
|
24
|
+
.vscode/
|
|
25
|
+
|
|
26
|
+
# Local secrets / scratch
|
|
27
|
+
.env
|
|
28
|
+
*.local
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 monkrel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kleinanzeigen-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial Python client + CLI for kleinanzeigen.de (Germany): search any category and get structured listing data (GPS, attributes, prices, images).
|
|
5
|
+
Project-URL: Homepage, https://github.com/monkrel/kleinanzeigen-api
|
|
6
|
+
Project-URL: Repository, https://github.com/monkrel/kleinanzeigen-api
|
|
7
|
+
Project-URL: Issues, https://github.com/monkrel/kleinanzeigen-api/issues
|
|
8
|
+
Author-email: monkrel <dev.monkrel@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,classifieds,ebay-kleinanzeigen,germany,kleinanzeigen,rentals,scraping
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: curl-cffi>=0.7
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
25
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# kleinanzeigen-api
|
|
29
|
+
|
|
30
|
+
Unofficial Python client + CLI for **[kleinanzeigen.de](https://www.kleinanzeigen.de)**,
|
|
31
|
+
Germany's classifieds marketplace (formerly *eBay Kleinanzeigen*). It talks to
|
|
32
|
+
the same mobile JSON API (`api.kleinanzeigen.de`) the official Android app uses.
|
|
33
|
+
|
|
34
|
+
- **Search any category** — cars, electronics, furniture, jobs, rentals… — by
|
|
35
|
+
keyword, location, price, and more (not just apartments).
|
|
36
|
+
- **`exclude` terms** to drop unwanted results (e.g. `defekt`, `bastler`).
|
|
37
|
+
- Returns **structured data the website never exposes**: GPS coordinates, exact
|
|
38
|
+
result counts, typed attributes (Wohnfläche, Zimmer, Nebenkosten, …), all
|
|
39
|
+
image sizes, ISO timestamps and price type.
|
|
40
|
+
|
|
41
|
+
> [!NOTE]
|
|
42
|
+
> This is for **Germany's kleinanzeigen.de only**, and is **not affiliated with, authorized, or endorsed
|
|
43
|
+
> by** Kleinanzeigen GmbH / Adevinta. It talks to a private app API and is
|
|
44
|
+
> provided for educational and personal use. See [Legal & etiquette](#legal--etiquette).
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install kleinanzeigen-api
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quickstart (library)
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from kleinanzeigen_api import KleinanzeigenAPI
|
|
56
|
+
|
|
57
|
+
api = KleinanzeigenAPI()
|
|
58
|
+
|
|
59
|
+
# Search EVERY category by keyword, newest first, excluding junk
|
|
60
|
+
ads = api.search(q="ThinkPad X1", exclude=["defekt", "bastler"],
|
|
61
|
+
sort_type="DATE_DESCENDING", pages=2)
|
|
62
|
+
for a in ads:
|
|
63
|
+
print(a.price, a.zip_code, a.city, a.title, a.url)
|
|
64
|
+
|
|
65
|
+
# Restrict to a category by NAME (or id) + a location, cheapest first
|
|
66
|
+
bikes = api.search("Berlin", category="Fahrräder & Zubehör", q="Rennrad",
|
|
67
|
+
distance_km=20, max_price=400, sort_type="PRICE_ASCENDING")
|
|
68
|
+
|
|
69
|
+
# Convenience wrapper for apartment rentals (category 203 = Mietwohnungen)
|
|
70
|
+
flats = api.search_rentals("Oranienburg", max_price=900, min_rooms=2,
|
|
71
|
+
exclude=["tausch", "wg-zimmer"], # works here too
|
|
72
|
+
sort_type="PRICE_ASCENDING")
|
|
73
|
+
for f in flats:
|
|
74
|
+
print(f.price, f.rooms, f.size_m2, f.latitude, f.longitude, f.attributes)
|
|
75
|
+
|
|
76
|
+
# A single ad by id
|
|
77
|
+
ad = api.get_ad("123456789")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`exclude` takes a string or a list and drops any result whose **title or
|
|
81
|
+
description** contains one of those terms (case-insensitive, applied
|
|
82
|
+
client-side). `q` is the server-side keyword.
|
|
83
|
+
|
|
84
|
+
### `Listing` fields
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
id, title, description, price, price_type, url, city, zip_code,
|
|
88
|
+
latitude, longitude, size_m2, rooms, posted, poster_type, images, attributes
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`attributes` is a `{localized_label: value}` dict of everything the ad carries
|
|
92
|
+
(`size_m2` and `rooms` are also surfaced as typed top-level fields).
|
|
93
|
+
|
|
94
|
+
## Quickstart (CLI)
|
|
95
|
+
|
|
96
|
+
Installing the package also adds a `kleinanzeigen-api` command
|
|
97
|
+
(`python -m kleinanzeigen_api` works too):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Search ALL categories by keyword, newest first, excluding junk
|
|
101
|
+
kleinanzeigen-api --q "ThinkPad X1" --exclude defekt,bastler --sort new
|
|
102
|
+
|
|
103
|
+
# Berlin within 20 km, a keyword, cheapest first, JSON to a file
|
|
104
|
+
kleinanzeigen-api Berlin --distance 20 --q "Rennrad" --max-price 400 \
|
|
105
|
+
--sort cheap --json --out bikes.json
|
|
106
|
+
|
|
107
|
+
# Restrict to a category id (203 = Wohnung mieten), 2+ rooms, 3 pages
|
|
108
|
+
kleinanzeigen-api Oranienburg --category 203 --max-price 900 \
|
|
109
|
+
--min-rooms 2 --pages 3 --sort cheap
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`--exclude` is repeatable or comma-separated. You can pass a numeric location id
|
|
113
|
+
instead of a name (`kleinanzeigen-api 3331` == Berlin). Run
|
|
114
|
+
`kleinanzeigen-api --help` for all flags.
|
|
115
|
+
|
|
116
|
+
## Categories — you never need to memorize ids
|
|
117
|
+
|
|
118
|
+
Pass a **name or an id** to `category`; names are resolved against a catalog of
|
|
119
|
+
all ~159 categories **bundled with the package** (works offline). Unknown or
|
|
120
|
+
ambiguous names raise a `ValueError` listing concrete suggestions.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from kleinanzeigen_api import find_categories, KleinanzeigenAPI
|
|
124
|
+
|
|
125
|
+
find_categories("Fahrr") # -> [Category(id='217', name='Fahrräder & Zubehör', …)]
|
|
126
|
+
KleinanzeigenAPI().search(category="Notebooks", q="ThinkPad") # by name
|
|
127
|
+
KleinanzeigenAPI().search(category=161, q="ThinkPad") # or by id
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
From the CLI, browse with `--categories` (offline, no request):
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
kleinanzeigen-api --categories # list all
|
|
134
|
+
kleinanzeigen-api --categories fahrr # filter
|
|
135
|
+
# 217 Auto, Rad & Boot > Fahrräder & Zubehör
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
> Category **names are German** (it's a German marketplace) — e.g. `Notebooks`,
|
|
139
|
+
> `Fahrräder & Zubehör`, `Mietwohnungen`. When unsure, `find_categories(...)` or
|
|
140
|
+
> `--categories <query>` shows the exact name and id. The bundled catalog can be
|
|
141
|
+
> refreshed from the live API with `KleinanzeigenAPI().fetch_categories()`.
|
|
142
|
+
|
|
143
|
+
## Search parameters
|
|
144
|
+
|
|
145
|
+
`search(location=None, *, q, exclude, category, category_id, distance_km,
|
|
146
|
+
min_price, max_price, min_rooms, max_rooms, min_size, max_size, ad_type,
|
|
147
|
+
sort_type, pages, size)`
|
|
148
|
+
|
|
149
|
+
- **location** — city/region name (resolved automatically) or a numeric id. An
|
|
150
|
+
unresolvable name raises `ValueError` (no silent nationwide fallback); pass
|
|
151
|
+
`location=None` to deliberately search all of Germany.
|
|
152
|
+
- **category** — name **or** id; `None` (default) searches **all categories**.
|
|
153
|
+
`category_id` is the raw-id alias (pass only one).
|
|
154
|
+
- **q** — server-side keyword. **exclude** — string or list; drops results whose
|
|
155
|
+
title/description contains any term (client-side, case-insensitive).
|
|
156
|
+
- **sort_type** — `PRICE_ASCENDING`, `PRICE_DESCENDING`, `DATE_DESCENDING`,
|
|
157
|
+
`DISTANCE_ASCENDING` (server-side).
|
|
158
|
+
- **min_rooms / max_rooms / min_size / max_size** — applied client-side; ignored
|
|
159
|
+
for ads without those attributes.
|
|
160
|
+
- **ad_type** — `OFFERED` (default) or `WANTED`. **pages / size** — paging.
|
|
161
|
+
|
|
162
|
+
`search_rentals(location, **kwargs)` is the same thing with `category_id=203`
|
|
163
|
+
("Mietwohnungen", apartments to rent) pre-set.
|
|
164
|
+
|
|
165
|
+
## How the transport works
|
|
166
|
+
|
|
167
|
+
A plain `requests` client is blocked at the TLS layer, and the API expects app
|
|
168
|
+
headers. This client:
|
|
169
|
+
|
|
170
|
+
- impersonates a real Chrome TLS fingerprint via [`curl_cffi`](https://github.com/lexiforest/curl_cffi),
|
|
171
|
+
- sends the app version + a self-generated `X-EBAYK-APP` install id
|
|
172
|
+
(a `uuid4` + millisecond timestamp, exactly how the app mints its own), and
|
|
173
|
+
- authenticates with the app's HTTP Basic credentials.
|
|
174
|
+
|
|
175
|
+
### Credentials & rotation
|
|
176
|
+
|
|
177
|
+
The Basic-auth username/password are **app-distribution values baked into the
|
|
178
|
+
Android client**, not personal secrets. They ship as defaults so `pip install`
|
|
179
|
+
just works — but Kleinanzeigen **can rotate them**. If you start getting
|
|
180
|
+
`401`/`403`, supply fresh values without editing the package:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
api = KleinanzeigenAPI(basic_user="…", basic_pw="…")
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
export KLEINANZEIGEN_BASIC_USER=…
|
|
188
|
+
export KLEINANZEIGEN_BASIC_PW=…
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Resolution order: constructor arg → environment variable → bundled default.
|
|
192
|
+
|
|
193
|
+
## Legal & etiquette
|
|
194
|
+
|
|
195
|
+
- Kleinanzeigen's Terms of Service **forbid automated access**. This library is
|
|
196
|
+
published for educational/personal use; **you are responsible** for how you
|
|
197
|
+
use it. Don't scrape at scale, don't redistribute the data, and don't build
|
|
198
|
+
anything that harms the service or its users.
|
|
199
|
+
- Be polite to the API: the client rate-limits to ~1.5 s/request by default
|
|
200
|
+
(with jitter). Don't lower it much, and cache results instead of tight polling.
|
|
201
|
+
- No warranty — see [LICENSE](LICENSE).
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
git clone https://github.com/monkrel/kleinanzeigen-api
|
|
207
|
+
cd kleinanzeigen-api
|
|
208
|
+
pip install -e ".[dev]"
|
|
209
|
+
pytest -q # offline parsing tests, no network
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
[MIT](LICENSE) © monkrel
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# kleinanzeigen-api
|
|
2
|
+
|
|
3
|
+
Unofficial Python client + CLI for **[kleinanzeigen.de](https://www.kleinanzeigen.de)**,
|
|
4
|
+
Germany's classifieds marketplace (formerly *eBay Kleinanzeigen*). It talks to
|
|
5
|
+
the same mobile JSON API (`api.kleinanzeigen.de`) the official Android app uses.
|
|
6
|
+
|
|
7
|
+
- **Search any category** — cars, electronics, furniture, jobs, rentals… — by
|
|
8
|
+
keyword, location, price, and more (not just apartments).
|
|
9
|
+
- **`exclude` terms** to drop unwanted results (e.g. `defekt`, `bastler`).
|
|
10
|
+
- Returns **structured data the website never exposes**: GPS coordinates, exact
|
|
11
|
+
result counts, typed attributes (Wohnfläche, Zimmer, Nebenkosten, …), all
|
|
12
|
+
image sizes, ISO timestamps and price type.
|
|
13
|
+
|
|
14
|
+
> [!NOTE]
|
|
15
|
+
> This is for **Germany's kleinanzeigen.de only**, and is **not affiliated with, authorized, or endorsed
|
|
16
|
+
> by** Kleinanzeigen GmbH / Adevinta. It talks to a private app API and is
|
|
17
|
+
> provided for educational and personal use. See [Legal & etiquette](#legal--etiquette).
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install kleinanzeigen-api
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quickstart (library)
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from kleinanzeigen_api import KleinanzeigenAPI
|
|
29
|
+
|
|
30
|
+
api = KleinanzeigenAPI()
|
|
31
|
+
|
|
32
|
+
# Search EVERY category by keyword, newest first, excluding junk
|
|
33
|
+
ads = api.search(q="ThinkPad X1", exclude=["defekt", "bastler"],
|
|
34
|
+
sort_type="DATE_DESCENDING", pages=2)
|
|
35
|
+
for a in ads:
|
|
36
|
+
print(a.price, a.zip_code, a.city, a.title, a.url)
|
|
37
|
+
|
|
38
|
+
# Restrict to a category by NAME (or id) + a location, cheapest first
|
|
39
|
+
bikes = api.search("Berlin", category="Fahrräder & Zubehör", q="Rennrad",
|
|
40
|
+
distance_km=20, max_price=400, sort_type="PRICE_ASCENDING")
|
|
41
|
+
|
|
42
|
+
# Convenience wrapper for apartment rentals (category 203 = Mietwohnungen)
|
|
43
|
+
flats = api.search_rentals("Oranienburg", max_price=900, min_rooms=2,
|
|
44
|
+
exclude=["tausch", "wg-zimmer"], # works here too
|
|
45
|
+
sort_type="PRICE_ASCENDING")
|
|
46
|
+
for f in flats:
|
|
47
|
+
print(f.price, f.rooms, f.size_m2, f.latitude, f.longitude, f.attributes)
|
|
48
|
+
|
|
49
|
+
# A single ad by id
|
|
50
|
+
ad = api.get_ad("123456789")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`exclude` takes a string or a list and drops any result whose **title or
|
|
54
|
+
description** contains one of those terms (case-insensitive, applied
|
|
55
|
+
client-side). `q` is the server-side keyword.
|
|
56
|
+
|
|
57
|
+
### `Listing` fields
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
id, title, description, price, price_type, url, city, zip_code,
|
|
61
|
+
latitude, longitude, size_m2, rooms, posted, poster_type, images, attributes
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`attributes` is a `{localized_label: value}` dict of everything the ad carries
|
|
65
|
+
(`size_m2` and `rooms` are also surfaced as typed top-level fields).
|
|
66
|
+
|
|
67
|
+
## Quickstart (CLI)
|
|
68
|
+
|
|
69
|
+
Installing the package also adds a `kleinanzeigen-api` command
|
|
70
|
+
(`python -m kleinanzeigen_api` works too):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Search ALL categories by keyword, newest first, excluding junk
|
|
74
|
+
kleinanzeigen-api --q "ThinkPad X1" --exclude defekt,bastler --sort new
|
|
75
|
+
|
|
76
|
+
# Berlin within 20 km, a keyword, cheapest first, JSON to a file
|
|
77
|
+
kleinanzeigen-api Berlin --distance 20 --q "Rennrad" --max-price 400 \
|
|
78
|
+
--sort cheap --json --out bikes.json
|
|
79
|
+
|
|
80
|
+
# Restrict to a category id (203 = Wohnung mieten), 2+ rooms, 3 pages
|
|
81
|
+
kleinanzeigen-api Oranienburg --category 203 --max-price 900 \
|
|
82
|
+
--min-rooms 2 --pages 3 --sort cheap
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`--exclude` is repeatable or comma-separated. You can pass a numeric location id
|
|
86
|
+
instead of a name (`kleinanzeigen-api 3331` == Berlin). Run
|
|
87
|
+
`kleinanzeigen-api --help` for all flags.
|
|
88
|
+
|
|
89
|
+
## Categories — you never need to memorize ids
|
|
90
|
+
|
|
91
|
+
Pass a **name or an id** to `category`; names are resolved against a catalog of
|
|
92
|
+
all ~159 categories **bundled with the package** (works offline). Unknown or
|
|
93
|
+
ambiguous names raise a `ValueError` listing concrete suggestions.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from kleinanzeigen_api import find_categories, KleinanzeigenAPI
|
|
97
|
+
|
|
98
|
+
find_categories("Fahrr") # -> [Category(id='217', name='Fahrräder & Zubehör', …)]
|
|
99
|
+
KleinanzeigenAPI().search(category="Notebooks", q="ThinkPad") # by name
|
|
100
|
+
KleinanzeigenAPI().search(category=161, q="ThinkPad") # or by id
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
From the CLI, browse with `--categories` (offline, no request):
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
kleinanzeigen-api --categories # list all
|
|
107
|
+
kleinanzeigen-api --categories fahrr # filter
|
|
108
|
+
# 217 Auto, Rad & Boot > Fahrräder & Zubehör
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> Category **names are German** (it's a German marketplace) — e.g. `Notebooks`,
|
|
112
|
+
> `Fahrräder & Zubehör`, `Mietwohnungen`. When unsure, `find_categories(...)` or
|
|
113
|
+
> `--categories <query>` shows the exact name and id. The bundled catalog can be
|
|
114
|
+
> refreshed from the live API with `KleinanzeigenAPI().fetch_categories()`.
|
|
115
|
+
|
|
116
|
+
## Search parameters
|
|
117
|
+
|
|
118
|
+
`search(location=None, *, q, exclude, category, category_id, distance_km,
|
|
119
|
+
min_price, max_price, min_rooms, max_rooms, min_size, max_size, ad_type,
|
|
120
|
+
sort_type, pages, size)`
|
|
121
|
+
|
|
122
|
+
- **location** — city/region name (resolved automatically) or a numeric id. An
|
|
123
|
+
unresolvable name raises `ValueError` (no silent nationwide fallback); pass
|
|
124
|
+
`location=None` to deliberately search all of Germany.
|
|
125
|
+
- **category** — name **or** id; `None` (default) searches **all categories**.
|
|
126
|
+
`category_id` is the raw-id alias (pass only one).
|
|
127
|
+
- **q** — server-side keyword. **exclude** — string or list; drops results whose
|
|
128
|
+
title/description contains any term (client-side, case-insensitive).
|
|
129
|
+
- **sort_type** — `PRICE_ASCENDING`, `PRICE_DESCENDING`, `DATE_DESCENDING`,
|
|
130
|
+
`DISTANCE_ASCENDING` (server-side).
|
|
131
|
+
- **min_rooms / max_rooms / min_size / max_size** — applied client-side; ignored
|
|
132
|
+
for ads without those attributes.
|
|
133
|
+
- **ad_type** — `OFFERED` (default) or `WANTED`. **pages / size** — paging.
|
|
134
|
+
|
|
135
|
+
`search_rentals(location, **kwargs)` is the same thing with `category_id=203`
|
|
136
|
+
("Mietwohnungen", apartments to rent) pre-set.
|
|
137
|
+
|
|
138
|
+
## How the transport works
|
|
139
|
+
|
|
140
|
+
A plain `requests` client is blocked at the TLS layer, and the API expects app
|
|
141
|
+
headers. This client:
|
|
142
|
+
|
|
143
|
+
- impersonates a real Chrome TLS fingerprint via [`curl_cffi`](https://github.com/lexiforest/curl_cffi),
|
|
144
|
+
- sends the app version + a self-generated `X-EBAYK-APP` install id
|
|
145
|
+
(a `uuid4` + millisecond timestamp, exactly how the app mints its own), and
|
|
146
|
+
- authenticates with the app's HTTP Basic credentials.
|
|
147
|
+
|
|
148
|
+
### Credentials & rotation
|
|
149
|
+
|
|
150
|
+
The Basic-auth username/password are **app-distribution values baked into the
|
|
151
|
+
Android client**, not personal secrets. They ship as defaults so `pip install`
|
|
152
|
+
just works — but Kleinanzeigen **can rotate them**. If you start getting
|
|
153
|
+
`401`/`403`, supply fresh values without editing the package:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
api = KleinanzeigenAPI(basic_user="…", basic_pw="…")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
export KLEINANZEIGEN_BASIC_USER=…
|
|
161
|
+
export KLEINANZEIGEN_BASIC_PW=…
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Resolution order: constructor arg → environment variable → bundled default.
|
|
165
|
+
|
|
166
|
+
## Legal & etiquette
|
|
167
|
+
|
|
168
|
+
- Kleinanzeigen's Terms of Service **forbid automated access**. This library is
|
|
169
|
+
published for educational/personal use; **you are responsible** for how you
|
|
170
|
+
use it. Don't scrape at scale, don't redistribute the data, and don't build
|
|
171
|
+
anything that harms the service or its users.
|
|
172
|
+
- Be polite to the API: the client rate-limits to ~1.5 s/request by default
|
|
173
|
+
(with jitter). Don't lower it much, and cache results instead of tight polling.
|
|
174
|
+
- No warranty — see [LICENSE](LICENSE).
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
git clone https://github.com/monkrel/kleinanzeigen-api
|
|
180
|
+
cd kleinanzeigen-api
|
|
181
|
+
pip install -e ".[dev]"
|
|
182
|
+
pytest -q # offline parsing tests, no network
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
[MIT](LICENSE) © monkrel
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kleinanzeigen-api"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Unofficial Python client + CLI for kleinanzeigen.de (Germany): search any category and get structured listing data (GPS, attributes, prices, images)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "monkrel", email = "dev.monkrel@gmail.com" }]
|
|
14
|
+
keywords = ["kleinanzeigen", "ebay-kleinanzeigen", "api", "scraping", "germany", "classifieds", "rentals"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"curl_cffi>=0.7",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest>=7",
|
|
32
|
+
"build>=1.0",
|
|
33
|
+
"twine>=5.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/monkrel/kleinanzeigen-api"
|
|
38
|
+
Repository = "https://github.com/monkrel/kleinanzeigen-api"
|
|
39
|
+
Issues = "https://github.com/monkrel/kleinanzeigen-api/issues"
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
kleinanzeigen-api = "kleinanzeigen_api.cli:main"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
path = "src/kleinanzeigen_api/__init__.py"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/kleinanzeigen_api"]
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.sdist]
|
|
51
|
+
include = [
|
|
52
|
+
"/src",
|
|
53
|
+
"/tests",
|
|
54
|
+
"/README.md",
|
|
55
|
+
"/LICENSE",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Unofficial Python client for the kleinanzeigen.de mobile JSON API.
|
|
2
|
+
|
|
3
|
+
This calls the real api.kleinanzeigen.de REST API used by the Android app of
|
|
4
|
+
Germany's Kleinanzeigen marketplace. It can search any category and returns
|
|
5
|
+
structured data the website doesn't show: GPS coordinates, exact result counts,
|
|
6
|
+
typed attributes, all image sizes, ISO timestamps and the price type.
|
|
7
|
+
|
|
8
|
+
Not affiliated with or endorsed by Kleinanzeigen GmbH / Adevinta. See the README
|
|
9
|
+
for the legal notes and rate-limiting advice.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from .categories import Category, all_categories, find_categories, get_category
|
|
14
|
+
from .client import KleinanzeigenAPI, Listing
|
|
15
|
+
|
|
16
|
+
__version__ = "0.1.0"
|
|
17
|
+
__all__ = [
|
|
18
|
+
"KleinanzeigenAPI",
|
|
19
|
+
"Listing",
|
|
20
|
+
"Category",
|
|
21
|
+
"find_categories",
|
|
22
|
+
"all_categories",
|
|
23
|
+
"get_category",
|
|
24
|
+
"__version__",
|
|
25
|
+
]
|