toapi is a Python web scraping tool that turns any website into a JSON API through declarative configuration.
The tool solves the problem of extracting structured data from web pages without building custom crawlers or maintaining databases. It works by letting you declare which fields to extract using CSS selectors, then automatically fetches pages on demand, parses them, and serves the results as JSON. Pages and parsed results are cached in memory to avoid redundant work. For JavaScript-heavy sites, you can pass a headless browser path to handle dynamic content.
The project suits developers who need quick, lightweight APIs over existing websites without the overhead of traditional web scraping infrastructure. It works well for small to medium projects where on-demand parsing is acceptable and you control the source URLs. The declarative approach means you describe what data you want rather than writing scraping logic. You can map multiple source URLs to clean API paths using route parameters, merge data from several websites, and add custom cleaning methods to transform values before returning them.
The project maintains a clean development workflow using uv for packaging and ruff for linting and formatting, with pre-commit hooks enforcing both. Contributions are welcomed through pull requests, with a requirement to discuss non-trivial changes in an issue first and ensure tests and linting pass before submission.