entirius-django-regon-api 3.0.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,6 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+
6
+ # Register your models here.
@@ -0,0 +1,10 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from django.apps import AppConfig
6
+
7
+
8
+ class DjangoRegonApiConfig(AppConfig):
9
+ default_auto_field = "django.db.models.BigAutoField"
10
+ name = "django_regon_api"
File without changes
@@ -0,0 +1,14 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from typing import ClassVar
6
+
7
+ from marshmallow import Schema
8
+ from marshmallow_dataclass import dataclass
9
+
10
+
11
+ @dataclass
12
+ class RegonParams:
13
+ raw_gus_data: bool | None = False
14
+ Schema: ClassVar[type[Schema]] = Schema
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from bievents import bi_django_command_decorator
6
+ from django.core.management.base import BaseCommand
7
+ from gov_rejestr_wl_sdk.services.client import GovRejestrWL
8
+
9
+
10
+ class Command(BaseCommand):
11
+ help = "Import data from gov-rejestr-wl by NIP"
12
+
13
+ def add_arguments(self, parser):
14
+ parser.add_argument("nip", type=str)
15
+
16
+ @bi_django_command_decorator
17
+ def handle(self, *args, **options):
18
+ nip = options["nip"]
19
+ print(f"NIP: {nip}")
20
+ client = GovRejestrWL()
21
+ result = client.search_by_nip(nip)
22
+ print(result)
@@ -0,0 +1,23 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+
6
+ from bievents import bi_django_command_decorator
7
+ from django.core.management.base import BaseCommand
8
+ from gov_rejestr_wl_sdk.services.client import GovRejestrWL
9
+
10
+
11
+ class Command(BaseCommand):
12
+ help = "Import data from gov-rejestr-wl by REGON"
13
+
14
+ def add_arguments(self, parser):
15
+ parser.add_argument("regon", type=str)
16
+
17
+ @bi_django_command_decorator
18
+ def handle(self, *args, **options):
19
+ regon = options["regon"]
20
+ print(f"regon: {regon}")
21
+ client = GovRejestrWL()
22
+ result = client.search_by_regon(regon)
23
+ print(result)
File without changes
@@ -0,0 +1,6 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+
6
+ # Create your models here.
@@ -0,0 +1,90 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from typing import Any
6
+
7
+ from django.core.cache import cache
8
+ from gov_rejestr_wl_sdk.services.client import GovRejestrWL
9
+ from process_logger import ProcessLogger
10
+
11
+ from django_regon_api import settings
12
+ from django_regon_api.settings import GOV_REJESTR_WL_USE_PROD_ENVIRONMENT
13
+
14
+ logger = ProcessLogger("django_regon_api.output")
15
+
16
+
17
+ def get_cache_key(nip: str, prefix: str = None) -> str:
18
+ return f"{prefix}:{nip}"
19
+
20
+
21
+ # used by
22
+ # django_vat_validator
23
+ def get_nip_from_gov(nip: str) -> tuple[Any, dict[str, Any] | None]:
24
+ """
25
+ Check if the provided NIP is a valid VAT payer using GUS GOV API (wl-api.mf.gov.pl).
26
+
27
+ This API only returns data for active VAT payers.
28
+ Personal NIPs that are not VAT registered will return null.
29
+
30
+ :param nip: The NIP to validate.
31
+ :return: Tuple (is_valid, data) - True if NIP is VAT registered, False otherwise.
32
+ """
33
+
34
+ if len(nip) > 2 and nip[:2].isalpha():
35
+ nip = nip[2:]
36
+ try:
37
+ cache_key = get_cache_key(nip, "django_regon_api_gus_gov")
38
+ cached_data = cache.get(cache_key)
39
+ if cached_data:
40
+ return True, cached_data
41
+
42
+ client = GovRejestrWL(use_prod_environment=GOV_REJESTR_WL_USE_PROD_ENVIRONMENT)
43
+ result = client.search_by_nip(nip, return_transformed=True)
44
+
45
+ cache.set(cache_key, result, settings.GET_GOV_DATA_CACHE_TIMEOUT)
46
+ return True, result
47
+ except Exception as e:
48
+ logger.exception(e)
49
+ return False, None
50
+
51
+
52
+ # used by
53
+ # django_vat_validator
54
+ def get_nip_from_regon_api(nip: str) -> tuple[bool, dict[str, Any] | None]:
55
+ """
56
+ Check if the provided NIP exists in REGON database (api.stat.gov.pl).
57
+
58
+ This API returns data for ALL registered entities including:
59
+ - Active VAT payers
60
+ - Personal NIPs (not VAT registered)
61
+ - Inactive entities
62
+
63
+ This is the proper way to validate if a NIP exists and get entity data,
64
+ regardless of VAT registration status.
65
+
66
+ :param nip: The NIP to validate (without country prefix).
67
+ :return: Tuple (is_valid, data) - True if NIP exists in REGON, False otherwise.
68
+ """
69
+ if len(nip) > 2 and nip[:2].isalpha():
70
+ nip = nip[2:]
71
+
72
+ try:
73
+ from django_regon_api.services.regon_client import RegonApiClient
74
+
75
+ cache_key = get_cache_key(nip, "django_regon_api_regon")
76
+ cached_data = cache.get(cache_key)
77
+ if cached_data:
78
+ return True, cached_data
79
+
80
+ client = RegonApiClient()
81
+ result = client.search_by_nip(nip, return_transformed=True)
82
+ if result:
83
+ cache.set(cache_key, result, settings.GET_REGON_DATA_CACHE_TIMEOUT)
84
+ return True, result
85
+ else:
86
+ return False, None
87
+
88
+ except Exception as e:
89
+ logger.exception(e)
90
+ return False, None
File without changes
@@ -0,0 +1,254 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ """
6
+ REGON API Client for BIR1 service (stat.gov.pl)
7
+
8
+ This client communicates with the official Polish Statistical Office (GUS)
9
+ REGON database API (BIR1) which provides data for all registered entities,
10
+ including personal taxpayer NIPs that are not VAT registered.
11
+
12
+ API Documentation: https://api.stat.gov.pl/Home/RegonApi
13
+ """
14
+
15
+ from typing import Any
16
+
17
+ from django.core.cache import cache
18
+ from process_logger import ProcessLogger, ProcessLoggerMixin
19
+ from zeep import Client
20
+ from zeep.cache import SqliteCache
21
+ from zeep.plugins import HistoryPlugin
22
+ from zeep.transports import Transport
23
+
24
+ from django_regon_api import settings
25
+
26
+
27
+ class RegonApiClient(ProcessLoggerMixin):
28
+ """
29
+ Client for REGON API (BIR1) - validates all NIPs including personal NIPs.
30
+
31
+ This is different from GUS_GOV provider which uses wl-api.mf.gov.pl
32
+ and only returns VAT registered entities.
33
+ """
34
+
35
+ def __init__(self, api_key: str = None, service_url: str = None, wsdl_url: str = None):
36
+ self._api_key = api_key or settings.BIR_API_KEY
37
+ self._service_url = service_url or settings.BIR_SERVICE_URL
38
+ self._wsdl_url = wsdl_url or settings.BIR_WSDL_URL
39
+ self._session_id = None
40
+ self._client = None
41
+ self._history = HistoryPlugin()
42
+ self.logger = ProcessLogger("django_regon_api.services.RegonApiClient")
43
+
44
+ def _get_client(self) -> Client:
45
+ """Get or create SOAP client."""
46
+ if not self._client:
47
+ transport = Transport(cache=SqliteCache())
48
+ self._client = Client(wsdl=self._wsdl_url, transport=transport, plugins=[self._history])
49
+ self._client.service._binding_options["address"] = self._service_url
50
+ return self._client
51
+
52
+ def _login(self) -> str:
53
+ """Login to REGON API and get session ID."""
54
+ if self._session_id:
55
+ return self._session_id
56
+
57
+ try:
58
+ client = self._get_client()
59
+ self._session_id = client.service.Zaloguj(self._api_key)
60
+ return self._session_id
61
+ except Exception as e:
62
+ self.logger.exception(e)
63
+ raise
64
+
65
+ def _logout(self):
66
+ """Logout from REGON API."""
67
+ if self._session_id:
68
+ try:
69
+ client = self._get_client()
70
+ client.service.Wyloguj(self._session_id)
71
+ self._session_id = None
72
+ except Exception as e:
73
+ self.logger.exception(e)
74
+
75
+ def _set_session_header(self):
76
+ """Set session ID in SOAP header."""
77
+ self._login()
78
+ self._get_client().transport.session.headers.update({"sid": self._session_id})
79
+
80
+ def get_cache_key(self, nip: str) -> str:
81
+ """Generate cache key for NIP."""
82
+ return f"{settings.GET_REGON_DATA_CACHE_PREFIX}:regon:{nip}"
83
+
84
+ def search_by_nip(self, nip: str, return_transformed: bool = True) -> dict[str, Any] | None:
85
+ """
86
+ Search entity by NIP in REGON database.
87
+
88
+ Args:
89
+ nip: NIP number (without country prefix)
90
+ return_transformed: Whether to return transformed data
91
+
92
+ Returns:
93
+ Dictionary with entity data or None if not found
94
+ """
95
+ cache_key = self.get_cache_key(nip)
96
+ cached_data = cache.get(cache_key)
97
+ if cached_data:
98
+ return cached_data
99
+ try:
100
+ self._set_session_header()
101
+ client = self._get_client()
102
+ result = client.service.DaneSzukajPodmioty(pParametryWyszukiwania={"Nip": nip})
103
+
104
+ if not result or result == "":
105
+ self.logger.info(f"No entity found for NIP: {nip}")
106
+ return None
107
+
108
+ import xml.etree.ElementTree as ET
109
+
110
+ root = ET.fromstring(result) # noqa: S314 — BIR SOAP payload; defusedxml swap tracked as tech debt
111
+
112
+ regon = None
113
+ for dane in root.findall(".//dane"):
114
+ regon_elem = dane.find("Regon")
115
+ if regon_elem is not None:
116
+ regon = regon_elem.text
117
+ break
118
+
119
+ if not regon:
120
+ self.logger.warning(f"REGON not found in response for NIP: {nip}")
121
+ return None
122
+
123
+ search_data = {}
124
+ for dane in root.findall(".//dane"):
125
+ for child in dane:
126
+ if child.text:
127
+ search_data[child.tag] = child.text
128
+
129
+ report_data = self._get_full_report(regon)
130
+
131
+ if report_data:
132
+ merged_data = {**search_data, **report_data}
133
+ else:
134
+ merged_data = search_data
135
+
136
+ if return_transformed:
137
+ transformed_data = self._transform_result(merged_data)
138
+ cache.set(cache_key, transformed_data, settings.GET_REGON_DATA_CACHE_TIMEOUT)
139
+ return transformed_data
140
+
141
+ return merged_data
142
+
143
+ except Exception as e:
144
+ self.logger.exception(e)
145
+ return None
146
+ finally:
147
+ self._logout()
148
+
149
+ def _get_full_report(self, regon: str) -> dict[str, Any] | None:
150
+ """Get full report for entity by REGON."""
151
+ try:
152
+ client = self._get_client()
153
+
154
+ # Determine report type based on REGON length
155
+ if len(regon) == 9:
156
+ report_name = "BIR11OsFizycznaDaneOgolne"
157
+ elif len(regon) == 14:
158
+ report_name = "BIR11JednLokalnaOsFizycznej"
159
+ else:
160
+ report_name = "BIR11OsPrawna"
161
+
162
+ result = client.service.DanePobierzPelnyRaport(pRegon=regon, pNazwaRaportu=report_name)
163
+
164
+ if not result or result == "":
165
+ return None
166
+
167
+ import xml.etree.ElementTree as ET
168
+
169
+ root = ET.fromstring(result) # noqa: S314 — BIR SOAP payload; defusedxml swap tracked as tech debt
170
+
171
+ data = {}
172
+ for child in root.iter():
173
+ if child.text and child.tag != root.tag:
174
+ data[child.tag] = child.text
175
+
176
+ return data
177
+
178
+ except Exception as e:
179
+ self.logger.exception(e)
180
+ return None
181
+
182
+ def _transform_result(self, result: dict[str, Any]) -> dict[str, Any]:
183
+ """
184
+ Transform REGON API response to common format compatible with other providers.
185
+
186
+ Maps REGON API fields to the format used by gov_rejestr_wl_sdk.
187
+ Supports both search result keys (Nazwa, Ulica) and full report keys (fiz_*, praw_*)
188
+ """
189
+ nazwa = (
190
+ result.get("Nazwa")
191
+ or result.get("fiz_nazwa")
192
+ or result.get("praw_nazwa")
193
+ or self._build_name_from_parts(result)
194
+ or ""
195
+ )
196
+
197
+ data_zakonczenia = (
198
+ result.get("DataZakonczeniaDzialalnosci")
199
+ or result.get("fiz_dataSkresleniaPodmiotuZRegon")
200
+ or result.get("praw_dataSkresleniaPodmiotuZRegon")
201
+ )
202
+ status_nip = "Nieczynny" if data_zakonczenia else "Czynny"
203
+
204
+ return {
205
+ "Nip": result.get("Nip") or result.get("fiz_nip") or result.get("praw_nip") or "",
206
+ "Nazwa": nazwa,
207
+ "StatusNip": status_nip,
208
+ "Regon": result.get("Regon") or result.get("fiz_regon9") or result.get("praw_regon14") or "",
209
+ "Ulica": result.get("Ulica") or result.get("fiz_adSiedzUlica") or result.get("praw_adSiedzUlica") or "",
210
+ "NrNieruchomosci": result.get("NrNieruchomosci")
211
+ or result.get("fiz_adSiedzNrNieruchomosci")
212
+ or result.get("praw_adSiedzNrNieruchomosci")
213
+ or "",
214
+ "NrLokalu": result.get("NrLokalu")
215
+ or result.get("fiz_adSiedzNrLokalu")
216
+ or result.get("praw_adSiedzNrLokalu")
217
+ or "",
218
+ "Miejscowosc": result.get("Miejscowosc")
219
+ or result.get("fiz_adSiedzMiejscowosc")
220
+ or result.get("praw_adSiedzMiejscowosc")
221
+ or "",
222
+ "KodPocztowy": result.get("KodPocztowy")
223
+ or result.get("fiz_adSiedzKodPocztowy")
224
+ or result.get("praw_adSiedzKodPocztowy")
225
+ or "",
226
+ "MiejscowoscPoczty": result.get("MiejscowoscPoczty")
227
+ or result.get("fiz_adSiedzMiejscowoscPoczty")
228
+ or result.get("praw_adSiedzMiejscowoscPoczty")
229
+ or "",
230
+ "Wojewodztwo": result.get("Wojewodztwo")
231
+ or result.get("fiz_adSiedzWojewodztwo_Nazwa")
232
+ or result.get("praw_adSiedzWojewodztwo_Nazwa")
233
+ or "",
234
+ "Powiat": result.get("Powiat")
235
+ or result.get("fiz_adSiedzPowiat_Nazwa")
236
+ or result.get("praw_adSiedzPowiat_Nazwa")
237
+ or "",
238
+ "Gmina": result.get("Gmina")
239
+ or result.get("fiz_adSiedzGmina_Nazwa")
240
+ or result.get("praw_adSiedzGmina_Nazwa")
241
+ or "",
242
+ "DataZakonczeniaDzialalnosci": data_zakonczenia,
243
+ "Typ": result.get("Typ") or ("F" if any(k.startswith("fiz_") for k in result.keys()) else "P"),
244
+ "SilosID": result.get("SilosID") or "",
245
+ }
246
+
247
+ def _build_name_from_parts(self, result: dict[str, Any]) -> str:
248
+ """Build full name from parts (nazwisko, imie1, imie2 for physical persons)."""
249
+ nazwisko = result.get("fiz_nazwisko", "")
250
+ imie1 = result.get("fiz_imie1", "")
251
+ imie2 = result.get("fiz_imie2", "")
252
+
253
+ parts = [p for p in [nazwisko, imie1, imie2] if p]
254
+ return " ".join(parts) if parts else ""
@@ -0,0 +1,25 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from django.conf import settings
6
+
7
+ BASE_URL = getattr(settings, "API_BASE_URL", "api").strip("/")
8
+
9
+ # GUS GOV settings (wl-api.mf.gov.pl - VAT payers only)
10
+ GOV_REJESTR_WL_USE_PROD_ENVIRONMENT = getattr(settings, "GOV_REJESTR_WL_USE_PROD_ENVIRONMENT", False)
11
+
12
+ # REGON API settings (api.stat.gov.pl - all NIPs including personal)
13
+ BIR_API_KEY = getattr(settings, "BIR_API_KEY", "abcde12345abcde12345") # Default test key
14
+ BIR_SERVICE_URL = getattr(
15
+ settings, "BIR_SERVICE_URL", "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc"
16
+ )
17
+ BIR_WSDL_URL = getattr(
18
+ settings, "BIR_WSDL_URL", "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-test.wsdl"
19
+ )
20
+ BIR_VERSIONS = getattr(settings, "BIR_VERSIONS", "bir1.1")
21
+
22
+ # Cache settings
23
+ GET_REGON_DATA_CACHE_PREFIX = getattr(settings, "GET_REGON_DATA_CACHE_PREFIX", "django_regon_api_get_data")
24
+ GET_REGON_DATA_CACHE_TIMEOUT = getattr(settings, "GET_REGON_DATA_CACHE_TIMEOUT", 60 * 60 * 1)
25
+ GET_GOV_DATA_CACHE_TIMEOUT = getattr(settings, "GET_GOV_DATA_CACHE_TIMEOUT", 60 * 60 * 1)
@@ -0,0 +1,15 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ from django.urls import include, path
6
+
7
+ from . import settings
8
+ from .views import api
9
+
10
+ paths = [
11
+ path("nip/<str:nip>/", api.search_by_nip, name="gov-rejestr-wl-nip"),
12
+ path("regon/<str:regon>/", api.search_by_regon, name="gov-rejestr-wl-regon"),
13
+ ]
14
+
15
+ urlpatterns = [path(f"{settings.BASE_URL}/regon/<str:version>/", include(paths))]
File without changes
@@ -0,0 +1 @@
1
+ from .gov import search_by_nip, search_by_regon
@@ -0,0 +1,45 @@
1
+ # This Source Code Form is subject to the terms of the Mozilla Public
2
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+
5
+ import logging
6
+
7
+ from django_utils.api.decorators import api_view, parse_parameters, require_http_method
8
+ from django_utils.api.exceptions import BadRequest
9
+ from django_utils.api.responses import Response
10
+ from gov_rejestr_wl_sdk.services.client import GovRejestrWL
11
+
12
+ from django_regon_api.dto.regon_params import RegonParams
13
+ from django_regon_api.settings import GOV_REJESTR_WL_USE_PROD_ENVIRONMENT
14
+
15
+ logger = logging.getLogger("debug")
16
+
17
+
18
+ @api_view
19
+ @parse_parameters(RegonParams.Schema())
20
+ @require_http_method("GET")
21
+ def search_by_nip(request, params: RegonParams, nip, *args, **kwargs):
22
+ # NIP
23
+ exception_code = 5001
24
+ try:
25
+ client = GovRejestrWL(use_prod_environment=GOV_REJESTR_WL_USE_PROD_ENVIRONMENT)
26
+ result = client.search_by_nip(nip, return_transformed=not params.raw_gus_data)
27
+ return Response(result)
28
+ except Exception as e:
29
+ logger.exception(e, extra={"code": exception_code})
30
+ raise BadRequest("No data found", exception_code) from e
31
+
32
+
33
+ @api_view
34
+ @parse_parameters(RegonParams.Schema())
35
+ @require_http_method("GET")
36
+ def search_by_regon(request, params: RegonParams, regon, *args, **kwargs):
37
+ # REGON
38
+ exception_code = 5003
39
+ try:
40
+ client = GovRejestrWL(use_prod_environment=GOV_REJESTR_WL_USE_PROD_ENVIRONMENT)
41
+ result = client.search_by_regon(regon, return_transformed=not params.raw_gus_data)
42
+ return Response(result)
43
+ except Exception as e:
44
+ logger.exception(e, extra={"code": exception_code})
45
+ raise BadRequest("No data found", exception_code) from e
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: entirius-django-regon-api
3
+ Version: 3.0.0
4
+ Summary: REGON/GUS lookup Django module for Volkanos — NIP/REGON search against Polish government registries
5
+ Project-URL: Repository, https://github.com/entirius/entirius-django-regon-api
6
+ Author: Entirius
7
+ Maintainer-email: Piotr Brzozowski <piotrb@entirius.com>, Paweł Kiełt <cptshooter12@gmail.com>, Mateusz Baran <mateuszbaranpv@gmail.com>, Michał Kloczkowski <michal@kloczkowski.pl>
8
+ License-Expression: MPL-2.0
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.11
11
+ Requires-Dist: django>=4.0.0
12
+ Requires-Dist: entirius-django-utils>=2.0.0
13
+ Requires-Dist: entirius-py-bievents>=2.0.0
14
+ Requires-Dist: entirius-py-gov-rejestr-wl-sdk>=2.0.0
15
+ Requires-Dist: entirius-py-process-logger>=2.0.0
16
+ Requires-Dist: marshmallow-dataclass>=8.5.3
17
+ Requires-Dist: marshmallow<4,>=3.15
18
+ Requires-Dist: zeep>=4.3.2
19
+ Provides-Extra: dev
20
+ Requires-Dist: pre-commit; extra == 'dev'
21
+ Requires-Dist: ruff; extra == 'dev'
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest; extra == 'test'
24
+ Requires-Dist: pytest-django; extra == 'test'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Django Regon API
28
+
29
+ REGON/GUS lookup Django module for Volkanos — a thin layer between other Django apps and Polish
30
+ government registries: REGON/BIR (`api.stat.gov.pl`, SOAP via `zeep`) and the VAT taxpayers
31
+ registry (`wl-api.mf.gov.pl` via `entirius-py-gov-rejestr-wl-sdk`).
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ uv pip install entirius-django-regon-api
37
+ ```
38
+
39
+ Add `django_regon_api` to `INSTALLED_APPS`.
40
+ Endpoints mount under `{API_BASE_URL}/regon/<version>/` (`nip/<nip>/`, `regon/<regon>/`).
41
+
42
+ Settings (all optional, sandbox defaults): `BIR_API_KEY`, `BIR_SERVICE_URL`, `BIR_WSDL_URL`,
43
+ `BIR_VERSIONS`, `GOV_REJESTR_WL_USE_PROD_ENVIRONMENT`, cache prefixes/timeouts —
44
+ reference in [AGENTS.md](AGENTS.md), BIR details in [docs/](docs/README.md).
45
+
46
+ ## Development and testing
47
+
48
+ ```bash
49
+ make install # uv sync, incl. extras
50
+ make check # ruff lint + format-check
51
+ make test # pytest
52
+ ```
@@ -0,0 +1,23 @@
1
+ django_regon_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ django_regon_api/admin.py,sha256=oaMowM2MrJ0SbCGQoB85EseGQpWjgq7v0MsMU1-VL68,231
3
+ django_regon_api/apps.py,sha256=cIcOBkvy9KSew3z-MBS0L-Ve1KfKUU-lNdU22y-Kd60,363
4
+ django_regon_api/models.py,sha256=WUlcZIEk6vZTY--2iiN2ZkdnkZYVf72ZjS8a_pBPw_Q,229
5
+ django_regon_api/output.py,sha256=7_MbZsGzFGnMNseYQFFwUAShsy1gJEJq1LEDmxWLYRA,2957
6
+ django_regon_api/settings.py,sha256=ggFIFECK6RAud-Shp2lo2j4GYd5a9qmp_s-I7pRN5Pg,1266
7
+ django_regon_api/urls.py,sha256=rEvGlWl5-iUQ2byIaUfJsV4TxzHOPyqR3JEaXkQYoAc,538
8
+ django_regon_api/dto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ django_regon_api/dto/regon_params.py,sha256=iD9RR76q8d6sVAU7hvCuSN3HwGaanTMVn68HnjvyWBQ,419
10
+ django_regon_api/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ django_regon_api/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ django_regon_api/management/commands/search_by_nip.py,sha256=MDgmCapUIeTR5piywAw2Zb3prG4q4LxYu-ClHtWSai0,756
13
+ django_regon_api/management/commands/search_by_regon.py,sha256=k0l68TVk7AaVUydmyXjFdRx6w2j5f8sBOrRnNO15e0U,773
14
+ django_regon_api/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ django_regon_api/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ django_regon_api/services/regon_client.py,sha256=juIE5ZOfGPmF0XMRAdMPm9P8XjXubWKVkY8UajADSYs,9610
17
+ django_regon_api/views/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ django_regon_api/views/api/__init__.py,sha256=aVKvPErE-tbma4zFOUGVWYcjvFLoaJUv70qnbgi7Tbc,48
19
+ django_regon_api/views/api/gov.py,sha256=8-FUou10GiR7l_7hQFSkSzgJu0r-3svFBS5WFod7B5o,1754
20
+ entirius_django_regon_api-3.0.0.dist-info/METADATA,sha256=vOh9WFxr67FR-8hgRnrUT_UuU0MkzhGcKgU3XNPkd2Y,1983
21
+ entirius_django_regon_api-3.0.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
22
+ entirius_django_regon_api-3.0.0.dist-info/licenses/LICENSE,sha256=Pz2eACSxkhsGfW9_iN60pgy-enjnbGTj8df8O3ebnQQ,16726
23
+ entirius_django_regon_api-3.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,373 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.