seao-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.
- seao_api-0.1.0/.gitignore +26 -0
- seao_api-0.1.0/CHANGELOG.md +54 -0
- seao_api-0.1.0/LICENSE +26 -0
- seao_api-0.1.0/PKG-INFO +174 -0
- seao_api-0.1.0/README.md +135 -0
- seao_api-0.1.0/docs/cli.md +203 -0
- seao_api-0.1.0/docs/configuration.md +228 -0
- seao_api-0.1.0/docs/getting-started.md +121 -0
- seao_api-0.1.0/docs/guides/detailed-databases.md +154 -0
- seao_api-0.1.0/docs/guides/filtering.md +153 -0
- seao_api-0.1.0/docs/guides/live-data.md +222 -0
- seao_api-0.1.0/docs/guides/opendata.md +172 -0
- seao_api-0.1.0/docs/index.md +59 -0
- seao_api-0.1.0/docs/legal.md +152 -0
- seao_api-0.1.0/docs/reference/files.md +112 -0
- seao_api-0.1.0/docs/reference/notice-structure.md +536 -0
- seao_api-0.1.0/docs/reference/opendata-structure.md +365 -0
- seao_api-0.1.0/docs/reference/search-api.md +443 -0
- seao_api-0.1.0/examples/01_open_tenders.py +38 -0
- seao_api-0.1.0/examples/02_single_notice.py +47 -0
- seao_api-0.1.0/examples/03_codes_and_buyers.py +31 -0
- seao_api-0.1.0/examples/04_opendata_history.py +52 -0
- seao_api-0.1.0/examples/05_detailed_database.py +56 -0
- seao_api-0.1.0/examples/README.md +20 -0
- seao_api-0.1.0/pyproject.toml +86 -0
- seao_api-0.1.0/src/seao_api/__init__.py +88 -0
- seao_api-0.1.0/src/seao_api/__main__.py +5 -0
- seao_api-0.1.0/src/seao_api/_http.py +171 -0
- seao_api-0.1.0/src/seao_api/_utils.py +191 -0
- seao_api-0.1.0/src/seao_api/_version.py +1 -0
- seao_api-0.1.0/src/seao_api/cli.py +383 -0
- seao_api-0.1.0/src/seao_api/clients/__init__.py +16 -0
- seao_api-0.1.0/src/seao_api/clients/avis.py +225 -0
- seao_api-0.1.0/src/seao_api/clients/fields.py +227 -0
- seao_api-0.1.0/src/seao_api/clients/search.py +276 -0
- seao_api-0.1.0/src/seao_api/config.py +334 -0
- seao_api-0.1.0/src/seao_api/detailed.py +280 -0
- seao_api-0.1.0/src/seao_api/exceptions.py +37 -0
- seao_api-0.1.0/src/seao_api/filtering.py +279 -0
- seao_api-0.1.0/src/seao_api/live.py +320 -0
- seao_api-0.1.0/src/seao_api/opendata/__init__.py +15 -0
- seao_api-0.1.0/src/seao_api/opendata/build.py +303 -0
- seao_api-0.1.0/src/seao_api/opendata/feed.py +93 -0
- seao_api-0.1.0/src/seao_api/py.typed +0 -0
- seao_api-0.1.0/tests/__init__.py +0 -0
- seao_api-0.1.0/tests/conftest.py +98 -0
- seao_api-0.1.0/tests/test_cli.py +77 -0
- seao_api-0.1.0/tests/test_config.py +112 -0
- seao_api-0.1.0/tests/test_filtering.py +77 -0
- seao_api-0.1.0/tests/test_live_and_detailed.py +186 -0
- seao_api-0.1.0/tests/test_network.py +28 -0
- seao_api-0.1.0/tests/test_opendata.py +109 -0
- seao_api-0.1.0/tests/test_utils_and_clients.py +158 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Data written by seao_api (results and the open-data database)
|
|
2
|
+
data/
|
|
3
|
+
seao_data/
|
|
4
|
+
|
|
5
|
+
# Scratch notebooks
|
|
6
|
+
test.ipynb
|
|
7
|
+
.ipynb_checkpoints/
|
|
8
|
+
|
|
9
|
+
# Python
|
|
10
|
+
__pycache__/
|
|
11
|
+
*.py[cod]
|
|
12
|
+
*.egg-info/
|
|
13
|
+
build/
|
|
14
|
+
dist/
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.coverage
|
|
21
|
+
htmlcov/
|
|
22
|
+
|
|
23
|
+
# Editors and OS
|
|
24
|
+
.vscode/
|
|
25
|
+
.idea/
|
|
26
|
+
.DS_Store
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project
|
|
5
|
+
uses [Semantic Versioning](https://semver.org/). Until 1.0, minor versions may
|
|
6
|
+
contain breaking changes.
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-27
|
|
11
|
+
|
|
12
|
+
First packaged release (`pip install seao-api`, `import seao_api`).
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Installable package with a `src/` layout, `pyproject.toml`, type marker (`py.typed`)
|
|
16
|
+
and a `seao` command (also `python -m seao_api`).
|
|
17
|
+
- `seao_api.configure()` and the `SEAO_DATA_DIR`, `SEAO_OUTPUT_DIR`,
|
|
18
|
+
`SEAO_OPENDATA_DIR`, `SEAO_REQUESTS_PER_SECOND` and `SEAO_USER_AGENT` environment variables.
|
|
19
|
+
- Separate locations for small result files (default `./seao_data`) and the large
|
|
20
|
+
open-data database (default: the per-user data folder). A `DataLocationWarning` is
|
|
21
|
+
emitted when the database goes to a folder you did not choose, or when disk space is low.
|
|
22
|
+
- `seao paths` shows the locations in effect.
|
|
23
|
+
- In-memory functions that write nothing: `fetch_open_tenders`, `fetch_avis`,
|
|
24
|
+
`fetch_filtered_avis`. The `save_*` functions write Parquet files and logs.
|
|
25
|
+
- `fetch_open_tenders(details=False)`: search rows only, in one request.
|
|
26
|
+
- `read_opendata(columns=...)`, `decode_json`, `columns_needed`, `log_to_console`.
|
|
27
|
+
- `seao open --no-save` and `seao avis --no-save` print a summary without writing files.
|
|
28
|
+
- A process-wide rate limit (2 requests/s by default) shared by every client, and
|
|
29
|
+
retries with backoff on HTTP 429/502/503/504 for every client (search and field
|
|
30
|
+
lookups included).
|
|
31
|
+
- Exceptions and warnings: `SEAOError`, `NotFoundError`, `AvisNotFoundError`,
|
|
32
|
+
`DatabaseNotFoundError`, `SEAOWarning`, `DataLocationWarning`, `ResultLimitWarning`.
|
|
33
|
+
- Offline test suite, CI workflow, PyPI publishing workflow, documentation and examples.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
- Modules moved from `src/api`, `src/atom`, `src/database` to the `seao_api` package.
|
|
37
|
+
- `SEAOClient` is renamed `SEAOSearchClient`.
|
|
38
|
+
- `fetch_open_tenders` / `fetch_avis` / `fetch_filtered_avis` now return DataFrames;
|
|
39
|
+
the old file-writing behaviour is `save_open_tenders` / `save_avis` / `save_filtered_avis`.
|
|
40
|
+
- `base_path` arguments are replaced by `output_dir` / `opendata_dir`. Files are written to
|
|
41
|
+
`<output_dir>/` instead of `<base_path>/data/custom/`, and the database lives in
|
|
42
|
+
`<opendata_dir>/` instead of `<base_path>/data/opendata/`. File names and log formats
|
|
43
|
+
are unchanged, so an existing folder can be reused by pointing to it.
|
|
44
|
+
- The clients send an honest `User-Agent` (`seao-api/<version>`) instead of imitating a browser.
|
|
45
|
+
- Progress messages go through `logging` (logger `seao_api`) instead of `print`.
|
|
46
|
+
- `main.py` is replaced by the `seao` command (`detaileddb` is kept as an alias of `detailed`).
|
|
47
|
+
- `save_filtered_avis` reads only the columns the filters need from the database.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
- Filters on a top-level column with an operator (`date_min=...`, `awards_exists=False`)
|
|
51
|
+
were read as a nested path.
|
|
52
|
+
- Buyer and contractor names with spaces or slashes are URL-encoded in
|
|
53
|
+
`SEAOFieldsClient.find_buyers` / `find_contractors`.
|
|
54
|
+
- `decode_json` and the filters handle pandas 3 string columns (missing values as `NaN`).
|
seao_api-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elouan SALAUN
|
|
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.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This license covers the source code of this project only. Data downloaded
|
|
26
|
+
with it belongs to its publishers and keeps its own terms: see docs/legal.md.
|
seao_api-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: seao-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial Python client and data tools for SEAO, Québec's public procurement system (live API and OCDS open data).
|
|
5
|
+
Project-URL: Homepage, https://github.com/elouansalaun/SEAO_API
|
|
6
|
+
Project-URL: Documentation, https://github.com/elouansalaun/SEAO_API/tree/main/docs
|
|
7
|
+
Project-URL: Issues, https://github.com/elouansalaun/SEAO_API/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/elouansalaun/SEAO_API/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Elouan SALAUN
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: appels-d-offres,ocds,open-contracting,open-data,procurement,public-procurement,quebec,québec,seao,tenders
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Natural Language :: French
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Topic :: Office/Business
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.10
|
|
30
|
+
Requires-Dist: numpy>=1.23
|
|
31
|
+
Requires-Dist: pandas>=2.0
|
|
32
|
+
Requires-Dist: platformdirs>=3
|
|
33
|
+
Requires-Dist: pyarrow>=12
|
|
34
|
+
Requires-Dist: requests>=2.28
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# seao-api
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/seao-api/)
|
|
43
|
+
[](https://pypi.org/project/seao-api/)
|
|
44
|
+
[](https://github.com/elouansalaun/SEAO_API/actions/workflows/ci.yml)
|
|
45
|
+
[](https://github.com/elouansalaun/SEAO_API/blob/main/LICENSE)
|
|
46
|
+
|
|
47
|
+
**Python access to [SEAO](https://seao.gouv.qc.ca), Québec's public procurement system**
|
|
48
|
+
(*Système électronique d'appel d'offres*): open tenders, notice details, bids,
|
|
49
|
+
awarded contracts and the full open-data history, as pandas DataFrames and
|
|
50
|
+
Parquet files.
|
|
51
|
+
|
|
52
|
+
> [!IMPORTANT]
|
|
53
|
+
> **Unofficial project**, not affiliated with or endorsed by the Gouvernement du
|
|
54
|
+
> Québec. The live API it uses is undocumented and can change without notice.
|
|
55
|
+
> SEAO is a public service: keep the default rate limit and read the
|
|
56
|
+
> [legal notice and responsible-use rules](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md)
|
|
57
|
+
> before running anything at scale.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Live SEAO data**: search open tenders by keyword, region, category,
|
|
62
|
+
buyer or date, and fetch everything SEAO shows about any notice
|
|
63
|
+
(description, documents list, addenda, bids received, contracts awarded,
|
|
64
|
+
final amount paid).
|
|
65
|
+
- **Open-data history**: download SEAO's weekly OCDS files into one local
|
|
66
|
+
Parquet database, kept up to date incrementally.
|
|
67
|
+
- **Filtering**: query nested OCDS fields with simple keywords
|
|
68
|
+
(`title_contains=`, `buyer_contains=`, `award_amount_min=`, ...), with no
|
|
69
|
+
JSON parsing to write.
|
|
70
|
+
- **Detailed databases**: filter the history, then fetch the full detail of
|
|
71
|
+
every matching notice.
|
|
72
|
+
- **In memory or on disk**: each `fetch_*` function returns a DataFrame and
|
|
73
|
+
writes nothing; each `save_*` function writes Parquet files and a log.
|
|
74
|
+
- **Polite by default**: one shared rate limit (2 requests/s), retries with
|
|
75
|
+
backoff on HTTP 429, and an honest User-Agent.
|
|
76
|
+
- **Command line**: `seao open`, `seao avis`, `seao opendata`,
|
|
77
|
+
`seao detailed`, `seao paths`.
|
|
78
|
+
|
|
79
|
+
## Install
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install seao-api
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Python 3.10+. Installs the `seao_api` package and the `seao` command.
|
|
86
|
+
|
|
87
|
+
## Quickstart
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import seao_api as seao
|
|
91
|
+
|
|
92
|
+
seao.log_to_console() # optional: show progress
|
|
93
|
+
|
|
94
|
+
# What is open now in Montréal? (one search request, nothing written)
|
|
95
|
+
df = seao.fetch_open_tenders(regions=[6], details=False)
|
|
96
|
+
print(df[["numero", "titre", "nomDonneurOuvrage", "dateFermetureUtc"]])
|
|
97
|
+
|
|
98
|
+
# Everything about one notice (UUID from the notice URL's ItemId=...)
|
|
99
|
+
one = seao.decode_json(seao.fetch_avis("ef852c0d-e273-4d40-9119-68e1847e020a"))
|
|
100
|
+
one.at[0, "consulter"]["avisResumeInformation"]["datePublicationUtc"]
|
|
101
|
+
|
|
102
|
+
# Save a detailed search as Parquet: ./seao_data/open_tender_cyber.parquet
|
|
103
|
+
seao.save_open_tenders(any_words=["cybersécurité", "SIEM"], suffix="cyber")
|
|
104
|
+
|
|
105
|
+
# Open-data history: build once (long), then update incrementally
|
|
106
|
+
seao.build_or_update()
|
|
107
|
+
rows = seao.read_opendata(["ocid", "date", "buyer", "tender", "awards"])
|
|
108
|
+
hits = seao.filter_tenders(rows, title_contains="déneigement", buyer_contains="laval")
|
|
109
|
+
|
|
110
|
+
# Full detail (bids, contracts, final amounts) of every matching notice
|
|
111
|
+
seao.save_filtered_avis(hits, suffix="deneigement_laval")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
From the terminal:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
seao open regions=6 details=false --no-save # print open tenders in Montréal
|
|
118
|
+
seao open regIds=6,13 catIds=43 suffix=mtl # save them with full details
|
|
119
|
+
seao avis ef852c0d-e273-4d40-9119-68e1847e020a # save one notice
|
|
120
|
+
seao opendata # build or update the history
|
|
121
|
+
seao detailed title_contains=véhicule buyer_contains=montreal suffix=vehicules_mtl
|
|
122
|
+
seao paths # where files are written
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Where files go
|
|
126
|
+
|
|
127
|
+
| What | Default location | Change it with |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| Results (`open_tender*.parquet`, `<uuid>*.parquet`, `filtered_avis*.parquet`) | `./seao_data/` in the current folder | `output_dir=`, `SEAO_OUTPUT_DIR`, `--output-dir` |
|
|
130
|
+
| Open-data database (several hundred MB, growing) | per-user data folder, e.g. `~/Library/Application Support/seao_api/opendata` | `opendata_dir=`, `SEAO_OPENDATA_DIR`, `--opendata-dir` |
|
|
131
|
+
|
|
132
|
+
To keep everything inside your project, call
|
|
133
|
+
`seao.configure(data_dir="./seao_data")` or set `SEAO_DATA_DIR=./seao_data`.
|
|
134
|
+
The first database build warns you where it is stored. Details:
|
|
135
|
+
[Configuration](https://github.com/elouansalaun/SEAO_API/blob/main/docs/configuration.md).
|
|
136
|
+
|
|
137
|
+
## Documentation
|
|
138
|
+
|
|
139
|
+
- [Getting started](https://github.com/elouansalaun/SEAO_API/blob/main/docs/getting-started.md)
|
|
140
|
+
- [Configuration](https://github.com/elouansalaun/SEAO_API/blob/main/docs/configuration.md): folders, environment variables, rate limit, logging
|
|
141
|
+
- [Command line](https://github.com/elouansalaun/SEAO_API/blob/main/docs/cli.md)
|
|
142
|
+
- Guides: [live data](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/live-data.md),
|
|
143
|
+
[open-data database](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/opendata.md),
|
|
144
|
+
[filtering](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/filtering.md),
|
|
145
|
+
[detailed databases](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/detailed-databases.md)
|
|
146
|
+
- Reference: [files and logs](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/files.md),
|
|
147
|
+
[open-data structure](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/opendata-structure.md),
|
|
148
|
+
[notice structure](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/notice-structure.md),
|
|
149
|
+
[search API and code lists](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/search-api.md)
|
|
150
|
+
- [Examples](https://github.com/elouansalaun/SEAO_API/tree/main/examples)
|
|
151
|
+
- [Legal notice and responsible use](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md)
|
|
152
|
+
|
|
153
|
+
## Data sources and licences
|
|
154
|
+
|
|
155
|
+
| Source | Used by | Terms |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| SEAO weekly open data ([open.canada.ca](https://open.canada.ca/data/en/dataset/d23b2e02-085d-43e5-9e6e-e1d558ebfdd5) / Données Québec) | `build_or_update`, `read_opendata` | [CC BY 4.0 (Québec)](https://www.donneesquebec.ca/fr/licence/): credit the source when you reuse it |
|
|
158
|
+
| SEAO's website API (`api.seao.gouv.qc.ca`) | `fetch_*`, `save_*`, clients | SEAO's terms of use; check them before redistributing |
|
|
159
|
+
|
|
160
|
+
Notice details contain names, phone numbers and e-mail addresses of
|
|
161
|
+
public-body and supplier staff. Do not republish them, and do not use them
|
|
162
|
+
for unsolicited messages: see the
|
|
163
|
+
[legal notice](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md#5-personal-information).
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
Issues and pull requests are welcome: see
|
|
168
|
+
[CONTRIBUTING.md](https://github.com/elouansalaun/SEAO_API/blob/main/CONTRIBUTING.md).
|
|
169
|
+
The test suite runs offline (`pip install -e ".[dev]" && pytest`).
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
The code is under the [MIT License](https://github.com/elouansalaun/SEAO_API/blob/main/LICENSE).
|
|
174
|
+
Data downloaded with it keeps its own terms (see above).
|
seao_api-0.1.0/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# seao-api
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/seao-api/)
|
|
4
|
+
[](https://pypi.org/project/seao-api/)
|
|
5
|
+
[](https://github.com/elouansalaun/SEAO_API/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/elouansalaun/SEAO_API/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
**Python access to [SEAO](https://seao.gouv.qc.ca), Québec's public procurement system**
|
|
9
|
+
(*Système électronique d'appel d'offres*): open tenders, notice details, bids,
|
|
10
|
+
awarded contracts and the full open-data history, as pandas DataFrames and
|
|
11
|
+
Parquet files.
|
|
12
|
+
|
|
13
|
+
> [!IMPORTANT]
|
|
14
|
+
> **Unofficial project**, not affiliated with or endorsed by the Gouvernement du
|
|
15
|
+
> Québec. The live API it uses is undocumented and can change without notice.
|
|
16
|
+
> SEAO is a public service: keep the default rate limit and read the
|
|
17
|
+
> [legal notice and responsible-use rules](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md)
|
|
18
|
+
> before running anything at scale.
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Live SEAO data**: search open tenders by keyword, region, category,
|
|
23
|
+
buyer or date, and fetch everything SEAO shows about any notice
|
|
24
|
+
(description, documents list, addenda, bids received, contracts awarded,
|
|
25
|
+
final amount paid).
|
|
26
|
+
- **Open-data history**: download SEAO's weekly OCDS files into one local
|
|
27
|
+
Parquet database, kept up to date incrementally.
|
|
28
|
+
- **Filtering**: query nested OCDS fields with simple keywords
|
|
29
|
+
(`title_contains=`, `buyer_contains=`, `award_amount_min=`, ...), with no
|
|
30
|
+
JSON parsing to write.
|
|
31
|
+
- **Detailed databases**: filter the history, then fetch the full detail of
|
|
32
|
+
every matching notice.
|
|
33
|
+
- **In memory or on disk**: each `fetch_*` function returns a DataFrame and
|
|
34
|
+
writes nothing; each `save_*` function writes Parquet files and a log.
|
|
35
|
+
- **Polite by default**: one shared rate limit (2 requests/s), retries with
|
|
36
|
+
backoff on HTTP 429, and an honest User-Agent.
|
|
37
|
+
- **Command line**: `seao open`, `seao avis`, `seao opendata`,
|
|
38
|
+
`seao detailed`, `seao paths`.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install seao-api
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Python 3.10+. Installs the `seao_api` package and the `seao` command.
|
|
47
|
+
|
|
48
|
+
## Quickstart
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import seao_api as seao
|
|
52
|
+
|
|
53
|
+
seao.log_to_console() # optional: show progress
|
|
54
|
+
|
|
55
|
+
# What is open now in Montréal? (one search request, nothing written)
|
|
56
|
+
df = seao.fetch_open_tenders(regions=[6], details=False)
|
|
57
|
+
print(df[["numero", "titre", "nomDonneurOuvrage", "dateFermetureUtc"]])
|
|
58
|
+
|
|
59
|
+
# Everything about one notice (UUID from the notice URL's ItemId=...)
|
|
60
|
+
one = seao.decode_json(seao.fetch_avis("ef852c0d-e273-4d40-9119-68e1847e020a"))
|
|
61
|
+
one.at[0, "consulter"]["avisResumeInformation"]["datePublicationUtc"]
|
|
62
|
+
|
|
63
|
+
# Save a detailed search as Parquet: ./seao_data/open_tender_cyber.parquet
|
|
64
|
+
seao.save_open_tenders(any_words=["cybersécurité", "SIEM"], suffix="cyber")
|
|
65
|
+
|
|
66
|
+
# Open-data history: build once (long), then update incrementally
|
|
67
|
+
seao.build_or_update()
|
|
68
|
+
rows = seao.read_opendata(["ocid", "date", "buyer", "tender", "awards"])
|
|
69
|
+
hits = seao.filter_tenders(rows, title_contains="déneigement", buyer_contains="laval")
|
|
70
|
+
|
|
71
|
+
# Full detail (bids, contracts, final amounts) of every matching notice
|
|
72
|
+
seao.save_filtered_avis(hits, suffix="deneigement_laval")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
From the terminal:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
seao open regions=6 details=false --no-save # print open tenders in Montréal
|
|
79
|
+
seao open regIds=6,13 catIds=43 suffix=mtl # save them with full details
|
|
80
|
+
seao avis ef852c0d-e273-4d40-9119-68e1847e020a # save one notice
|
|
81
|
+
seao opendata # build or update the history
|
|
82
|
+
seao detailed title_contains=véhicule buyer_contains=montreal suffix=vehicules_mtl
|
|
83
|
+
seao paths # where files are written
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Where files go
|
|
87
|
+
|
|
88
|
+
| What | Default location | Change it with |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| Results (`open_tender*.parquet`, `<uuid>*.parquet`, `filtered_avis*.parquet`) | `./seao_data/` in the current folder | `output_dir=`, `SEAO_OUTPUT_DIR`, `--output-dir` |
|
|
91
|
+
| Open-data database (several hundred MB, growing) | per-user data folder, e.g. `~/Library/Application Support/seao_api/opendata` | `opendata_dir=`, `SEAO_OPENDATA_DIR`, `--opendata-dir` |
|
|
92
|
+
|
|
93
|
+
To keep everything inside your project, call
|
|
94
|
+
`seao.configure(data_dir="./seao_data")` or set `SEAO_DATA_DIR=./seao_data`.
|
|
95
|
+
The first database build warns you where it is stored. Details:
|
|
96
|
+
[Configuration](https://github.com/elouansalaun/SEAO_API/blob/main/docs/configuration.md).
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
- [Getting started](https://github.com/elouansalaun/SEAO_API/blob/main/docs/getting-started.md)
|
|
101
|
+
- [Configuration](https://github.com/elouansalaun/SEAO_API/blob/main/docs/configuration.md): folders, environment variables, rate limit, logging
|
|
102
|
+
- [Command line](https://github.com/elouansalaun/SEAO_API/blob/main/docs/cli.md)
|
|
103
|
+
- Guides: [live data](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/live-data.md),
|
|
104
|
+
[open-data database](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/opendata.md),
|
|
105
|
+
[filtering](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/filtering.md),
|
|
106
|
+
[detailed databases](https://github.com/elouansalaun/SEAO_API/blob/main/docs/guides/detailed-databases.md)
|
|
107
|
+
- Reference: [files and logs](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/files.md),
|
|
108
|
+
[open-data structure](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/opendata-structure.md),
|
|
109
|
+
[notice structure](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/notice-structure.md),
|
|
110
|
+
[search API and code lists](https://github.com/elouansalaun/SEAO_API/blob/main/docs/reference/search-api.md)
|
|
111
|
+
- [Examples](https://github.com/elouansalaun/SEAO_API/tree/main/examples)
|
|
112
|
+
- [Legal notice and responsible use](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md)
|
|
113
|
+
|
|
114
|
+
## Data sources and licences
|
|
115
|
+
|
|
116
|
+
| Source | Used by | Terms |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| SEAO weekly open data ([open.canada.ca](https://open.canada.ca/data/en/dataset/d23b2e02-085d-43e5-9e6e-e1d558ebfdd5) / Données Québec) | `build_or_update`, `read_opendata` | [CC BY 4.0 (Québec)](https://www.donneesquebec.ca/fr/licence/): credit the source when you reuse it |
|
|
119
|
+
| SEAO's website API (`api.seao.gouv.qc.ca`) | `fetch_*`, `save_*`, clients | SEAO's terms of use; check them before redistributing |
|
|
120
|
+
|
|
121
|
+
Notice details contain names, phone numbers and e-mail addresses of
|
|
122
|
+
public-body and supplier staff. Do not republish them, and do not use them
|
|
123
|
+
for unsolicited messages: see the
|
|
124
|
+
[legal notice](https://github.com/elouansalaun/SEAO_API/blob/main/docs/legal.md#5-personal-information).
|
|
125
|
+
|
|
126
|
+
## Contributing
|
|
127
|
+
|
|
128
|
+
Issues and pull requests are welcome: see
|
|
129
|
+
[CONTRIBUTING.md](https://github.com/elouansalaun/SEAO_API/blob/main/CONTRIBUTING.md).
|
|
130
|
+
The test suite runs offline (`pip install -e ".[dev]" && pytest`).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
The code is under the [MIT License](https://github.com/elouansalaun/SEAO_API/blob/main/LICENSE).
|
|
135
|
+
Data downloaded with it keeps its own terms (see above).
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Command line
|
|
2
|
+
|
|
3
|
+
Installing seao-api adds a `seao` command. `python -m seao_api` does the
|
|
4
|
+
same thing.
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
seao [--version] [--help] COMMAND [options] [key=value ...]
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
| Command | Does | Writes |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| [`seao open`](#seao-open) | Search the tenders open now, with their details | `<output>/open_tender[_<suffix>].parquet` |
|
|
13
|
+
| [`seao avis`](#seao-avis) | Fetch every section of one notice | `<output>/<uuid>[_<suffix>].parquet` |
|
|
14
|
+
| [`seao opendata`](#seao-opendata) | Build or update the open-data database | `<opendata>/opendata.parquet` |
|
|
15
|
+
| [`seao detailed`](#seao-detailed) | Filter the open data, then fetch every matching notice | `<output>/filtered_avis[_<suffix>].parquet` |
|
|
16
|
+
| [`seao paths`](#seao-paths) | Show where files are written | nothing |
|
|
17
|
+
|
|
18
|
+
Each command prints the path of the file it wrote on stdout, and its
|
|
19
|
+
progress on stderr. Exit codes: `0` success, `1` error (bad value, network,
|
|
20
|
+
missing database), `2` invalid command line, `130` interrupted with Ctrl+C.
|
|
21
|
+
|
|
22
|
+
## Common options
|
|
23
|
+
|
|
24
|
+
Every command accepts these options, before or after its `key=value`
|
|
25
|
+
arguments:
|
|
26
|
+
|
|
27
|
+
| Option | Effect |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `--data-dir DIR` | Result files in `DIR`, database in `DIR/opendata` |
|
|
30
|
+
| `--output-dir DIR` | Folder for result files (default `./seao_data`) |
|
|
31
|
+
| `--opendata-dir DIR` | Folder of the database (default: per-user data folder) |
|
|
32
|
+
| `--requests-per-second N`, `--rps N` | Shared request rate (default 2) |
|
|
33
|
+
| `-q`, `--quiet` | Print only warnings and errors |
|
|
34
|
+
| `-v`, `--verbose` | Also print debug messages |
|
|
35
|
+
|
|
36
|
+
The same settings can come from environment variables: see
|
|
37
|
+
[Configuration](configuration.md#environment-variables).
|
|
38
|
+
|
|
39
|
+
## Writing `key=value` arguments
|
|
40
|
+
|
|
41
|
+
- Lists are comma-separated: `regIds=6,13`.
|
|
42
|
+
- Booleans: `true`, `1`, `yes`, `y` or `oui` mean true. Anything else means false.
|
|
43
|
+
- `open` also accepts the query-string form: `"regIds=6,13&catIds=43"`. A part
|
|
44
|
+
without `=` adds a value to the previous key, so `"regIds=6&13"` means
|
|
45
|
+
`regIds=6,13`.
|
|
46
|
+
- **Quote** any argument that contains `&`, `!`, `*`, `?`, spaces or
|
|
47
|
+
parentheses. Use **single quotes** for regular expressions: inside double
|
|
48
|
+
quotes, bash and zsh rewrite `!`.
|
|
49
|
+
|
|
50
|
+
## `seao open`
|
|
51
|
+
|
|
52
|
+
Search SEAO for the tenders open now and save them, one row per notice.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
seao open # every open tender, with details (long)
|
|
56
|
+
seao open details=false # search rows only: one request
|
|
57
|
+
seao open regIds=6,13 catIds=43 suffix=mtl # Montréal + Laval, category S7
|
|
58
|
+
seao open flTxtAnyWrds=pompe*,cyber searchDoc=true
|
|
59
|
+
seao open regions=6 --no-save # print a summary, write nothing
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
"Open" means: status *Publié* (`statIds=6`), one of SEAO's public notice
|
|
63
|
+
types, and a closing date today or later. This is the definition SEAO's home
|
|
64
|
+
page uses. The criteria you pass are added to it, and can replace it:
|
|
65
|
+
`statIds=...`, `tpIds=...`, `open_on=2026-12-01`, `open_on=` (keep notices
|
|
66
|
+
whose closing date has passed), `all_types=true` (drop the type filter).
|
|
67
|
+
|
|
68
|
+
**Search criteria.** Use either the SEAO query-string name or the Python
|
|
69
|
+
name:
|
|
70
|
+
|
|
71
|
+
| SEAO name | Python name | Value |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `regIds` | `regions` | Region ids |
|
|
74
|
+
| `catIds` | `categories` | SEAO category ids |
|
|
75
|
+
| `unIds` | `subcategories` | UNSPSC codes (a prefix such as `43` matches the branch) |
|
|
76
|
+
| `tpIds` | `types` | Notice type ids |
|
|
77
|
+
| `statIds` | `statuses` | Status ids |
|
|
78
|
+
| `flTxtAnyWrds` | `any_words` | Keywords: any of them |
|
|
79
|
+
| `flTxtAllWrds` | `all_words` | Keywords: all of them |
|
|
80
|
+
| `flTxtNoWrds` | `no_words` | Keywords to exclude |
|
|
81
|
+
| `searchDoc` | `search_in_documents` | Also search the text of the tender documents |
|
|
82
|
+
| `dtePubFrm`, `dtePubTo` | `date_pub_from`, `date_pub_to` | Publication date range (`YYYY-MM-DD` or ISO timestamp) |
|
|
83
|
+
| `dteFermFrm`, `dteFermTo` | `date_ferm_from`, `date_ferm_to` | Closing date range |
|
|
84
|
+
| `selDoIds` | `buyer_ids` | Buyer UUIDs |
|
|
85
|
+
| `selContIds` | `contractor_ids` | Contractor UUIDs |
|
|
86
|
+
| | `open_on` | Day the notices must still be open on (default today; empty = no closing-date filter) |
|
|
87
|
+
| | `all_types` | `true` to drop the notice type filter |
|
|
88
|
+
|
|
89
|
+
Ids are listed in the [search API reference](reference/search-api.md#field-dictionaries).
|
|
90
|
+
Any other key is sent to the API unchanged, e.g. `isArchive=false`.
|
|
91
|
+
|
|
92
|
+
Each keyword is searched as an exact phrase. A keyword containing `*` is a
|
|
93
|
+
wildcard (`pomp*` matches *pompe*, *pompes*, *pompier*). Long keyword lists
|
|
94
|
+
are split into several requests automatically.
|
|
95
|
+
|
|
96
|
+
**Run options:**
|
|
97
|
+
|
|
98
|
+
| Key | Default | Effect |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `suffix` | none | Save as `open_tender_<suffix>.parquet` |
|
|
101
|
+
| `details` | `true` | `false`: keep only the search rows (one request, no detail columns) |
|
|
102
|
+
| `max_workers` | `4` | Notices fetched at the same time (they share the rate limit) |
|
|
103
|
+
| `requests_per_second` | shared limit | Request rate for this run |
|
|
104
|
+
|
|
105
|
+
`--no-save` prints the number, title, buyer and closing date of each notice
|
|
106
|
+
instead of writing a file. It implies `details=false` unless you set
|
|
107
|
+
`details=true`.
|
|
108
|
+
|
|
109
|
+
The file is **replaced** by the next run with the same suffix. A search
|
|
110
|
+
returns at most 2,000 notices: when it hits that cap, a warning is printed
|
|
111
|
+
and the log line says `capped=True`. Split the search by region, category or
|
|
112
|
+
date range.
|
|
113
|
+
|
|
114
|
+
## `seao avis`
|
|
115
|
+
|
|
116
|
+
Fetch every public section of one notice.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
seao avis ef852c0d-e273-4d40-9119-68e1847e020a
|
|
120
|
+
seao avis ef852c0d-e273-4d40-9119-68e1847e020a suffix=before-addendum
|
|
121
|
+
seao avis 'https://seao.gouv.qc.ca/avis-resultat-recherche/consulter?ItemId=ef852c0d-e273-4d40-9119-68e1847e020a'
|
|
122
|
+
seao avis ef852c0d-e273-4d40-9119-68e1847e020a --no-save
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The notice is identified by its UUID: the `uuid` column of a search result,
|
|
126
|
+
or the `ItemId=` value of the notice page URL (the whole URL also works). The
|
|
127
|
+
numeric `id` and the `numero` (`2026-1986`) are not accepted.
|
|
128
|
+
|
|
129
|
+
`suffix=NAME` is the only `key=value` option. The file is replaced when the
|
|
130
|
+
same notice is saved again with the same suffix; use suffixes to keep
|
|
131
|
+
several versions. `--no-save` prints the identity of the notice and the
|
|
132
|
+
sections SEAO shows for it.
|
|
133
|
+
|
|
134
|
+
Any notice works: open, closed, cancelled, awarded, archived. If the notice
|
|
135
|
+
cannot be fetched, a `FAILED` line is logged, the error is printed, and no
|
|
136
|
+
file is written.
|
|
137
|
+
|
|
138
|
+
## `seao opendata`
|
|
139
|
+
|
|
140
|
+
Build the open-data database from every weekly file of the SEAO feed, or, if
|
|
141
|
+
it exists, merge only the files not processed yet.
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
seao opendata
|
|
145
|
+
seao opendata --opendata-dir ./seao_data/opendata
|
|
146
|
+
seao opendata --batch-size 10
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The first build downloads every weekly file published so far: expect a long
|
|
150
|
+
run and several hundred MB on disk. Later runs take seconds to minutes.
|
|
151
|
+
`--batch-size N` sets how many files are merged at a time (default 20).
|
|
152
|
+
Details: [Open-data database](guides/opendata.md).
|
|
153
|
+
|
|
154
|
+
## `seao detailed`
|
|
155
|
+
|
|
156
|
+
Filter the open-data database with `filter_tenders`, find the notice UUID of
|
|
157
|
+
every matching row, and fetch each notice's full detail from the live API,
|
|
158
|
+
one notice at a time. `detaileddb` is an alias.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
seao detailed title_contains=véhicule,voiture buyer_contains=montreal \
|
|
162
|
+
procurement_method=open main_category=goods suffix=vehicules_mtl
|
|
163
|
+
seao detailed classification_id_startswith=7612 award_amount_min=100000 delay=2
|
|
164
|
+
seao detailed 'title_regex=(?i)^(?!.*pièce).*$' title_contains=camion suffix=camions
|
|
165
|
+
seao detailed buyer_contains=laval source=./my_subset.parquet
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Filter keys** are the `filter_tenders` keyword names: a shortcut (`title`,
|
|
169
|
+
`buyer`, `supplier`, `classification_id`, `procurement_method`,
|
|
170
|
+
`main_category`, `award_amount`, `tender_start`, ...) or a dotted path
|
|
171
|
+
(`tender.items.classification.id`), followed by an optional operator:
|
|
172
|
+
`_contains`, `_startswith`, `_regex`, `_in`, `_min`, `_max`, `_exists`.
|
|
173
|
+
Without an operator the value must be equal. See
|
|
174
|
+
[Filtering the open data](guides/filtering.md).
|
|
175
|
+
|
|
176
|
+
- Values are comma-separated lists, except for `_regex` keys, whose value is
|
|
177
|
+
kept whole. Repeat a `_regex` key to give several patterns.
|
|
178
|
+
- `_min` / `_max` values that are numbers become numbers; dates stay text.
|
|
179
|
+
- `_exists` takes a boolean.
|
|
180
|
+
|
|
181
|
+
**Run options:**
|
|
182
|
+
|
|
183
|
+
| Key | Default | Effect |
|
|
184
|
+
|---|---|---|
|
|
185
|
+
| `suffix` | none | Save as `filtered_avis_<suffix>.parquet` |
|
|
186
|
+
| `delay` | `1` | Seconds to wait between two notices, on top of the rate limit |
|
|
187
|
+
| `match` | `all` | `all`: every filter must hold; `any`: at least one |
|
|
188
|
+
| `source` | local database | Parquet file to filter instead of the database |
|
|
189
|
+
|
|
190
|
+
Progress is printed after each notice, with the time left. Ctrl+C stops the
|
|
191
|
+
run: the notices fetched so far are still written, and the log line says
|
|
192
|
+
`interrupted=True`.
|
|
193
|
+
|
|
194
|
+
## `seao paths`
|
|
195
|
+
|
|
196
|
+
Print the folders in effect and where each value comes from (argument,
|
|
197
|
+
`configure`, environment variable or default), and whether the database
|
|
198
|
+
exists.
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
seao paths
|
|
202
|
+
SEAO_DATA_DIR=./seao_data seao paths
|
|
203
|
+
```
|