Download the PHP package beziworld/laravel-gus-bdl without Composer
On this page you can find all versions of the php package beziworld/laravel-gus-bdl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beziworld/laravel-gus-bdl
More information about beziworld/laravel-gus-bdl
Files in beziworld/laravel-gus-bdl
Package laravel-gus-bdl
Short Description Laravel client for the GUS Local Data Bank (Bank Danych Lokalnych, BDL) API: subjects, variables, territorial units, statistical data series, ETag caching and quota-aware rate limiting
License MIT
Homepage https://github.com/beziworld/laravel-gus-bdl
Informations about the package laravel-gus-bdl
Laravel GUS BDL
Laravel client for the Local Data Bank API of Statistics Poland (GUS, Bank Danych Lokalnych, BDL): the largest Polish database of economic, social and environmental statistics for Poland, voivodeships, counties, communes and statistical localities, from 1995 onwards.
- subjects (tematy), variables (zmienne), territorial units and statistical localities with search
- data by variable (many units) and by unit (many variables), as typed
DataSerieswith values per year and the attribute (flag) of every value - dictionaries: attributes, measure units, aggregates, years, levels, metadata, version
- lazy pagination with
LazyCollection: further pages are requested only while you iterate - lookup of units by TERYT code (
"1261011"gives the commune of Kraków) - response cache with ETag revalidation (
If-None-Match) - client-side rate limiter that follows the documented quotas and shares the budget between workers
- optional client key (
X-ClientId) for higher limits, Polish and English, JSON, JSON:API and XML bdl:searchandbdl:dataArtisan commands
Polska wersja dokumentacji
Why this package
At the time of writing Packagist has no package for the BDL API (searches for "bdl gus" and "bank danych lokalnych" return nothing; the GUS packages that exist cover the REGON registry). Clients exist for Python, R and C#, none for PHP. This package adds a typed, cached and quota-aware Laravel client.
Installation
Everything works anonymously. Optional .env settings:
Subjects and variables
Territorial units and TERYT codes
A BDL unit id has twelve digits: macroregion, voivodeship, region, subregion, county, commune and commune type.
The voivodeship, county, commune and type parts are the TERC code, so terytCode() works offline. For the
reverse direction unitByTeryt() walks down the hierarchy (three small cached requests at most). To keep a local
copy of the TERYT register itself, see laravel-teryt.
Data
Every DataPoint has year, value and attributeId. Attribute 1 marks a regular value; other attributes describe
missing, confidential, estimated or incomplete values, which the API still returns (usually as 0). Read their
meaning from GusBdl::attributes() (symbol x, a, s, M, ...). aggregateId selects another aggregation (see
GusBdl::aggregates()).
Dictionaries, languages and formats
Quotas, rate limiting and caching
The documented quotas are:
| Window | Anonymous | With X-ClientId |
|---|---|---|
| 1 second | 5 | 10 |
| 15 minutes | 100 | 500 |
| 12 hours | 1 000 | 5 000 |
| 7 days | 10 000 | 50 000 |
The client counts requests in these windows in a cache store before sending them. When the per-second window is
full it waits (up to GUS_BDL_RATE_LIMIT_MAX_WAIT seconds); when a longer window is full it throws
RateLimitExceeded with retryAfter instead of spending the remaining budget. Use a shared store (Redis, database)
so that queue workers and web requests count together. The API may enforce lower anonymous quotas than documented
(its HTTP 429 messages have mentioned 50 requests per 15 minutes and 100 per 12 hours); stricter values can be set in
config/gus-bdl.php under rate_limit.limits, and registering a free key is the practical fix.
On HTTP 429 the client reads Retry-After (sent as "340 sek"), throws RateLimitExceeded and refuses further
requests locally until the block expires, so a loop does not keep hammering the API.
Responses are cached. A cached response is served without any request while it is fresh (the API sends
max-age=1800; override with GUS_BDL_CACHE_TTL). Afterwards it is revalidated with If-None-Match; on
304 Not Modified the cached body is reused. Dictionaries change rarely, so a long TTL is safe for them.
Artisan
Errors
| Situation | Result |
|---|---|
| HTTP 404 (unknown id), unknown TERYT code | NotFound (httpStatus, path, errorCode) |
| HTTP 429 from the API | RateLimitExceeded (retryAfter, window, fromServer = true) |
| Local quota exhausted or server block still active | RateLimitExceeded (fromServer = false for a local quota) |
| HTTP 4xx (for example 412 for page size above 100), HTTP 5xx after retries | ApiException (httpStatus, errorCode, isServerError()) |
| Connection failure or timeout after retries | ApiException wrapping the ConnectionException |
| Body that is not JSON | ApiException |
Invalid configuration (GUS_BDL_LANG, page size, URL, limits) |
InvalidConfiguration |
| Empty search phrase, invalid TERYT code length, no variable ids | InvalidArgumentException |
All package exceptions extend Beziworld\GusBdl\Exceptions\GusBdlException.
Development
Tests use responses captured from the live API (tests/Fixtures); no request leaves the test suite.
Author
Created and maintained by Kamil Ćwiertnia, beziworld.eu.
- E-mail: [email protected]
- Issues: GitHub issues
Need an integration? Get in touch through beziworld.eu.
Other packages by the author
laravel-teryt · laravel-krs · laravel-company-data · laravel-nbp
License
MIT. See LICENSE.md. The data is published by Statistics Poland (Główny Urząd Statystyczny) under the Creative Commons Attribution 4.0 licence; credit GUS as the source when you republish it. This package is not affiliated with or endorsed by Statistics Poland.
All versions of laravel-gus-bdl with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.8
illuminate/cache Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0