euipo-tm-client 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.
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ansel Halliburton
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,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: euipo-tm-client
3
+ Version: 0.1.0
4
+ Summary: Minimal Python client for the EUIPO trademark search API
5
+ Project-URL: Homepage, https://github.com/anseljh/euipo-tm-client
6
+ Project-URL: Repository, https://github.com/anseljh/euipo-tm-client
7
+ Project-URL: Issues, https://github.com/anseljh/euipo-tm-client/issues
8
+ Author-email: Ansel Halliburton <anseljh@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: api-client,euipo,intellectual-property,ip,trademark
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Legal Industry
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: httpx>=0.28.1
26
+ Description-Content-Type: text/markdown
27
+
28
+ # euipo-tm-client
29
+
30
+ Minimal Python client for the [EUIPO](https://euipo.europa.eu/) (European Union
31
+ Intellectual Property Office) trademark search API.
32
+
33
+ It is a thin, synchronous wrapper (built on [`httpx`](https://www.python-httpx.org/))
34
+ that handles OAuth2 authentication and returns responses as raw parsed JSON
35
+ (`dict`). It covers the two core endpoints: searching for trade marks and
36
+ retrieving the details of a single trade mark.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install euipo-tm-client
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ The client reads credentials from environment variables (you can keep them in a
47
+ `.env` file in the working directory — real environment variables take
48
+ precedence):
49
+
50
+ | Variable | Description |
51
+ | ------------------- | --------------------------------------------- |
52
+ | `EUIPO_API_KEY` | Your application's client ID |
53
+ | `EUIPO_API_SECRET` | Your application's client secret |
54
+ | `EUIPO_ENVIRONMENT` | `"sandbox"` (default) or `"production"` |
55
+
56
+ Obtain credentials and subscribe your application to the *Trademark search* API
57
+ plan via the [EUIPO developer portal](https://dev-sandbox.euipo.europa.eu/).
58
+
59
+ ## Usage
60
+
61
+ ```python
62
+ from euipo_tm_client import TrademarkSearchClient
63
+
64
+ with TrademarkSearchClient() as client:
65
+ # Search using an RSQL query expression.
66
+ results = client.search_trademarks(
67
+ query="wordMarkSpecification.verbalElement==apple",
68
+ size=10,
69
+ )
70
+ print(results["totalElements"])
71
+ for tm in results["trademarks"]:
72
+ print(tm["applicationNumber"], tm.get("status"))
73
+
74
+ # Retrieve full details for one trade mark.
75
+ detail = client.get_trademark("018692868", language="en")
76
+ print(detail["status"])
77
+ ```
78
+
79
+ Credentials and environment can also be passed explicitly instead of via the
80
+ environment:
81
+
82
+ ```python
83
+ client = TrademarkSearchClient(
84
+ api_key="...", api_secret="...", environment="production",
85
+ )
86
+ ```
87
+
88
+ ### Errors
89
+
90
+ API and authentication failures raise typed exceptions, all subclasses of
91
+ `EUIPOError`:
92
+
93
+ - `EUIPOAuthError` — token acquisition failed.
94
+ - `EUIPOAPIError` — the API returned a non-2xx response; exposes `.status_code`
95
+ and the parsed `.body`.
96
+
97
+ ## Query language (RSQL)
98
+
99
+ The `query` argument of `search_trademarks()` accepts an **RSQL** (REST Query
100
+ Language) expression — a compact, URL-friendly filter syntax. A clause is
101
+ `field` + `operator` + `value`, and clauses combine with `and` / `or` (use
102
+ parentheses to group). RSQL avoids unsafe characters, so no URL encoding is
103
+ needed.
104
+
105
+ Comparison operators:
106
+
107
+ | Operator | Meaning |
108
+ | ------------------ | ---------------------------------------- |
109
+ | `==` | equal to (supports `*` as a wildcard) |
110
+ | `!=` | not equal to (supports `*` as a wildcard)|
111
+ | `<` `<=` `>` `>=` | range comparison (dates and numbers) |
112
+ | `=in=` | in a set, e.g. `=in=(WORD,FIGURATIVE)` |
113
+ | `=out=` | not in a set |
114
+ | `=all=` | contains all of a set |
115
+
116
+ Each field supports only a subset of these operators. Date fields
117
+ (`applicationDate`, `registrationDate`, `expiryDate`, …) expect `yyyy-MM-dd`
118
+ values. Examples:
119
+
120
+ ```text
121
+ # Verbal element exactly "apple"
122
+ wordMarkSpecification.verbalElement==apple
123
+
124
+ # Wildcard match + status, with nice-class membership
125
+ niceClasses=all=(25,28,40) and wordMarkSpecification.verbalElement==*Dog* and status==REGISTERED
126
+
127
+ # Date range with grouped OR logic
128
+ applicationDate>=2023-05-04 and ((markFeature==FIGURATIVE and niceClasses=all=(25,26)) or (markFeature==WORD and niceClasses=out=(40)))
129
+ ```
130
+
131
+ The full grammar, the list of supported fields, and the operators each field
132
+ allows are documented in the `query` parameter of the OpenAPI spec
133
+ (`specs/openapi.json`).
134
+
135
+ ## Development
136
+
137
+ This project is managed with [`uv`](https://docs.astral.sh/uv/).
138
+
139
+ ```bash
140
+ uv sync # install dependencies
141
+ uv run pytest # run the test suite (mocks HTTP; no live credentials needed)
142
+ uv run main.py # run the live sandbox demo (requires credentials)
143
+ ```
144
+
145
+ ## License
146
+
147
+ [MIT](LICENSE)
@@ -0,0 +1,120 @@
1
+ # euipo-tm-client
2
+
3
+ Minimal Python client for the [EUIPO](https://euipo.europa.eu/) (European Union
4
+ Intellectual Property Office) trademark search API.
5
+
6
+ It is a thin, synchronous wrapper (built on [`httpx`](https://www.python-httpx.org/))
7
+ that handles OAuth2 authentication and returns responses as raw parsed JSON
8
+ (`dict`). It covers the two core endpoints: searching for trade marks and
9
+ retrieving the details of a single trade mark.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install euipo-tm-client
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ The client reads credentials from environment variables (you can keep them in a
20
+ `.env` file in the working directory — real environment variables take
21
+ precedence):
22
+
23
+ | Variable | Description |
24
+ | ------------------- | --------------------------------------------- |
25
+ | `EUIPO_API_KEY` | Your application's client ID |
26
+ | `EUIPO_API_SECRET` | Your application's client secret |
27
+ | `EUIPO_ENVIRONMENT` | `"sandbox"` (default) or `"production"` |
28
+
29
+ Obtain credentials and subscribe your application to the *Trademark search* API
30
+ plan via the [EUIPO developer portal](https://dev-sandbox.euipo.europa.eu/).
31
+
32
+ ## Usage
33
+
34
+ ```python
35
+ from euipo_tm_client import TrademarkSearchClient
36
+
37
+ with TrademarkSearchClient() as client:
38
+ # Search using an RSQL query expression.
39
+ results = client.search_trademarks(
40
+ query="wordMarkSpecification.verbalElement==apple",
41
+ size=10,
42
+ )
43
+ print(results["totalElements"])
44
+ for tm in results["trademarks"]:
45
+ print(tm["applicationNumber"], tm.get("status"))
46
+
47
+ # Retrieve full details for one trade mark.
48
+ detail = client.get_trademark("018692868", language="en")
49
+ print(detail["status"])
50
+ ```
51
+
52
+ Credentials and environment can also be passed explicitly instead of via the
53
+ environment:
54
+
55
+ ```python
56
+ client = TrademarkSearchClient(
57
+ api_key="...", api_secret="...", environment="production",
58
+ )
59
+ ```
60
+
61
+ ### Errors
62
+
63
+ API and authentication failures raise typed exceptions, all subclasses of
64
+ `EUIPOError`:
65
+
66
+ - `EUIPOAuthError` — token acquisition failed.
67
+ - `EUIPOAPIError` — the API returned a non-2xx response; exposes `.status_code`
68
+ and the parsed `.body`.
69
+
70
+ ## Query language (RSQL)
71
+
72
+ The `query` argument of `search_trademarks()` accepts an **RSQL** (REST Query
73
+ Language) expression — a compact, URL-friendly filter syntax. A clause is
74
+ `field` + `operator` + `value`, and clauses combine with `and` / `or` (use
75
+ parentheses to group). RSQL avoids unsafe characters, so no URL encoding is
76
+ needed.
77
+
78
+ Comparison operators:
79
+
80
+ | Operator | Meaning |
81
+ | ------------------ | ---------------------------------------- |
82
+ | `==` | equal to (supports `*` as a wildcard) |
83
+ | `!=` | not equal to (supports `*` as a wildcard)|
84
+ | `<` `<=` `>` `>=` | range comparison (dates and numbers) |
85
+ | `=in=` | in a set, e.g. `=in=(WORD,FIGURATIVE)` |
86
+ | `=out=` | not in a set |
87
+ | `=all=` | contains all of a set |
88
+
89
+ Each field supports only a subset of these operators. Date fields
90
+ (`applicationDate`, `registrationDate`, `expiryDate`, …) expect `yyyy-MM-dd`
91
+ values. Examples:
92
+
93
+ ```text
94
+ # Verbal element exactly "apple"
95
+ wordMarkSpecification.verbalElement==apple
96
+
97
+ # Wildcard match + status, with nice-class membership
98
+ niceClasses=all=(25,28,40) and wordMarkSpecification.verbalElement==*Dog* and status==REGISTERED
99
+
100
+ # Date range with grouped OR logic
101
+ applicationDate>=2023-05-04 and ((markFeature==FIGURATIVE and niceClasses=all=(25,26)) or (markFeature==WORD and niceClasses=out=(40)))
102
+ ```
103
+
104
+ The full grammar, the list of supported fields, and the operators each field
105
+ allows are documented in the `query` parameter of the OpenAPI spec
106
+ (`specs/openapi.json`).
107
+
108
+ ## Development
109
+
110
+ This project is managed with [`uv`](https://docs.astral.sh/uv/).
111
+
112
+ ```bash
113
+ uv sync # install dependencies
114
+ uv run pytest # run the test suite (mocks HTTP; no live credentials needed)
115
+ uv run main.py # run the live sandbox demo (requires credentials)
116
+ ```
117
+
118
+ ## License
119
+
120
+ [MIT](LICENSE)
@@ -0,0 +1,15 @@
1
+ """Minimal Python client for the EUIPO trademark search API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .client import TrademarkSearchClient
6
+ from .config import Settings
7
+ from .errors import EUIPOAPIError, EUIPOAuthError, EUIPOError
8
+
9
+ __all__ = [
10
+ "TrademarkSearchClient",
11
+ "Settings",
12
+ "EUIPOError",
13
+ "EUIPOAuthError",
14
+ "EUIPOAPIError",
15
+ ]
@@ -0,0 +1,82 @@
1
+ """OAuth2 client-credentials authentication for the EUIPO trademark search API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+
7
+ import httpx
8
+
9
+ from .errors import EUIPOAuthError
10
+
11
+ # Refresh slightly before the token actually expires to avoid races near the boundary.
12
+ _EXPIRY_SAFETY_MARGIN_SECONDS = 60
13
+
14
+
15
+ class OAuth2ClientCredentials:
16
+ """Fetches and caches an OAuth2 access token using the client-credentials flow.
17
+
18
+ The EUIPO API authenticates applications anonymously: we POST the client id
19
+ and secret to the token endpoint and receive a bearer token, which is cached
20
+ until shortly before it expires.
21
+ """
22
+
23
+ def __init__(
24
+ self,
25
+ *,
26
+ client_id: str,
27
+ client_secret: str,
28
+ token_url: str,
29
+ http_client: httpx.Client,
30
+ scope: str = "uid",
31
+ ) -> None:
32
+ self._client_id = client_id
33
+ self._client_secret = client_secret
34
+ self._token_url = token_url
35
+ self._http = http_client
36
+ self._scope = scope
37
+ self._token: str | None = None
38
+ self._expires_at: float = 0.0
39
+
40
+ def get_token(self, *, force_refresh: bool = False) -> str:
41
+ """Return a valid bearer token, fetching a new one when needed."""
42
+ if not force_refresh and self._token is not None and time.monotonic() < self._expires_at:
43
+ return self._token
44
+ return self._fetch_token()
45
+
46
+ def _fetch_token(self) -> str:
47
+ try:
48
+ response = self._http.post(
49
+ self._token_url,
50
+ data={
51
+ "grant_type": "client_credentials",
52
+ "client_id": self._client_id,
53
+ "client_secret": self._client_secret,
54
+ "scope": self._scope,
55
+ },
56
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
57
+ )
58
+ except httpx.HTTPError as exc:
59
+ raise EUIPOAuthError(f"Token request to {self._token_url} failed: {exc}") from exc
60
+
61
+ if response.status_code != httpx.codes.OK:
62
+ raise EUIPOAuthError(
63
+ f"Token request failed with status {response.status_code}: {response.text!r}"
64
+ )
65
+
66
+ try:
67
+ payload = response.json()
68
+ except ValueError as exc:
69
+ raise EUIPOAuthError(f"Token response was not valid JSON: {response.text!r}") from exc
70
+
71
+ token = payload.get("access_token")
72
+ if not token:
73
+ raise EUIPOAuthError(f"Token response did not contain an access_token: {payload!r}")
74
+
75
+ expires_in = payload.get("expires_in", 0)
76
+ try:
77
+ expires_in = int(expires_in)
78
+ except (TypeError, ValueError):
79
+ expires_in = 0
80
+ self._token = token
81
+ self._expires_at = time.monotonic() + max(expires_in - _EXPIRY_SAFETY_MARGIN_SECONDS, 0)
82
+ return token