Lightweight Python client for interacting with the e-bloc platform (e-bloc.ro).
- Overview: short project summary and purpose
- Quick Start: minimal usage example for
Ebloky - Architecture: high-level components and responsibilities
- Implementation Details: important internals and design choices
- Usage & Examples: example code and common calls
- Best Practices: recommended patterns for safe usage
- License: MIT license and liability
ebloky is a small library that wraps the e-bloc AJAX endpoints and provides
convenient methods to load a session and fetch common resources such as
discussion subjects, replies, monthly documents and apartment/home data.
The library focuses on a pragmatic mapping from endpoint names to simple Python calls while providing a RequestManager that centralizes request construction and execution.
Install the package (from source or your packaging flow), then use Ebloky:
from pathlib import Path
from ebloky import Ebloky
e = Ebloky(verbose=1)
# either load a session dictionary you already have
session = {
"PHPSESSID": "YOUR_SESSION_ID",
"ASID": 123,
"APID": 456,
"username": "you@example.com",
}
e.loadssession(session)
# helper methods: list available apartments and set ids used by other calls
available = e.getAvaiableAp()
print("Available apartments:", available)
# set association or apartment id for subsequent calls
e.setAsID(123)
e.setApID(456)
# Example: download documents that match a filename pattern in a date range
from datetime import date
import re
pattern = re.compile(r".*invoice.*")
success, count, paths = e.getDocsInRange(
pattern=pattern,
start=date(2025, 9, 1),
end=date(2025, 10, 31),
out_dir=Path("./documents"),
)
if success:
print(f"Downloaded {count} documents to: {paths}")Ebloky(wrapper): Public API used by callers. Holds aRequestManagerand asessiondict. Exposes convenience methods likegetDiscutions,getDocumentsForMonth, anddownloadDocument.RequestManager: Responsible for forging requests (headers, cookies, endpoints, payloads) and executing HTTP calls viarequests.- Logging: a small custom
Loggerattaches a TRACE level and writes both toebloky.log(file) and stdout with configurable verbosity. - Service matrix:
RequestManager.forgeRequestmaps simple service keys (e.g.AjaxGetHomeAp,DownloadAvizierDoc) to URLs, payload defaults and output types. This keeps per-endpoint details centralized.
- Cookie/session model:
RequestManagerkeeps a cookie template with keys such asPHPSESSID,ASID,APID,username. UseEbloky.loadssession()to populate the live session values the library will use to buildCookieheaders. - Request forging:
forgeRequest(service, sessiondata, custom)returns a request descriptor withmethod,url,header,payload,paramsand anoutputtype.executeRequest()runs the HTTP call and attempts to decode JSON; if decoding fails it falls back totextorbytesdepending on the declaredoutput. - Return shapes:
executeRequest()returns a(status_code, data)tuple; theEblokywrapper methods usually discard status and return parsed data. - File downloads:
downloadDocument(docid, path)will write the raw bytes returned from theDownloadAvizierDocendpoint to the givenPath.
- Load a session from file:
from pathlib import Path
from ebloky import Ebloky
e = Ebloky()
e.loadsession(Path("./session.json"))- List discussion subjects and replies:
- List discussion subjects and replies:
# `getDiscutions` aggregates subjects and their replies into a mapping
disc = e.getDiscutions(cap=100)
for subj_id, subj in disc.items():
print(subj.get("titlu"))
for r in subj.get("replays", []):
print(" -", r.get("titlu"))- Check if documents exist for a month and download one:
- Check if documents exist for a month and download matching files:
- Retrieve document IDs without downloading:
# the availability helper also accepts an optional compiled regex pattern
# which will perform a quick title search within the month instead of only
# checking for the month’s existence.
if e.documentsAvailableFor(2025, 10):
# Prefer the range/pattern downloader for batch operations; low-level
# single-file download helpers are intentionally private.
from datetime import date
import re
pattern = re.compile(r".*invoice.*")
e.getDocsInRange(
pattern=pattern,
start=date(2025, 9, 1),
end=date(2025, 10, 31),
out_dir=Path("./invoices"),
)
# example use of the new helper to just get IDs:
# (if a regex is provided and exactly one document matches, the method
# returns the integer id directly instead of a one-element list)
ids = e.getDocumentIdsInRange(start=date(2025, 10, 1), end=date(2025, 10, 31))
print("IDs in range:", ids)- Secure sessions: store
PHPSESSIDand other sensitive session data outside source control and load them at runtime (e.g. environment, secrets manager, or an encrypted local store). - Error handling: many methods trust endpoint responses. Wrap calls in try/except and validate data shapes before use.
- Rate limiting & retry:
RequestManagerreducesallowreqon each call; add retry/backoff logic and respect the remote service's usage policies. The library also supports arequestcapfeature: passrequestcaptoEbloky()to limit how many outbound requests the internal manager will perform during a run. Query the remaining allowance withe.getRemainingRequests(). - Tests & mocking: when writing tests, mock
requests.postandrequests.getand assert the right payloads and headers are sent.
- Logging: the module configures a custom TRACE level for very verbose
diagnostics. Configure the module-level logger (see the
Loggerclass) or instantiateLoggerdirectly to enable TRACE output. Theverboseargument onEbloky()is currently reserved and not applied by the instance. - Endpoint matrix: to add or adjust endpoint behavior, update
RequestManager.forgeRequest()where service keys are mapped tourl,payload,paramsandoutputtypes.
- This project is licensed under the MIT License. See the
LICENSEfile for details.
- This software is provided "as is", without warranty of any kind. The authors and contributors are not liable for any damages arising from use of this software.
- The API documentation and examples in this repository have been compiled purely for educational purposes and to demonstrate how one may interact with the e-bloc platform. No attempt has been made to bypass protections, harm the service, or infringe on any rights. All information is derived from the public-facing interface and is presented under the principles of fair use. The author disclaims any intent or responsibility for misuse and seeks to be fully exonerated from any legal or ethical claims related to these materials.