{"id":45568714,"url":"https://github.com/bframe-work/bframelib","last_synced_at":"2026-02-23T07:01:09.945Z","repository":{"id":272842304,"uuid":"913537651","full_name":"bframe-work/bframelib","owner":"bframe-work","description":"Open source billing library based in SQL. Generate, view and diff invoices locally or in the cloud.","archived":false,"fork":false,"pushed_at":"2025-04-04T19:26:02.000Z","size":176,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-03T09:08:25.125Z","etag":null,"topics":["duckdb","python","sql"],"latest_commit_sha":null,"homepage":"https://bframe.work","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bframe-work.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-07T21:58:08.000Z","updated_at":"2025-04-04T19:26:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"a7bc4c22-9c07-40b0-85c9-7af8eba7e490","html_url":"https://github.com/bframe-work/bframelib","commit_stats":null,"previous_names":["bframe-work/bframelib"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bframe-work/bframelib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bframe-work%2Fbframelib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bframe-work%2Fbframelib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bframe-work%2Fbframelib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bframe-work%2Fbframelib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bframe-work","download_url":"https://codeload.github.com/bframe-work/bframelib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bframe-work%2Fbframelib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29739024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T04:51:08.365Z","status":"ssl_error","status_checked_at":"2026-02-23T04:49:15.865Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["duckdb","python","sql"],"created_at":"2026-02-23T07:00:34.897Z","updated_at":"2026-02-23T07:01:09.939Z","avatar_url":"https://github.com/bframe-work.png","language":"Python","readme":"# bframe\n\n[bframe](https://bframe.work) is a library to generate, view and diff invoices locally.\n\nKey technical features:\n* **Pure SQL** - bframe's business logic is entirely written in customizable SQL views.\n* **No infrastructure** - The library is fully in process with no hosting or docker required.\n* **Choose your source** - Utilizing [duckdb](https://duckdb.org/) extensions, many sources of data are supported (Postgres, S3 compatible, etc).\n\nKey billing use cases supported:\n* **Complex pricing and packaging** - Supports pricing usage, subscriptions or custom [user defined views](https://bframe.work/features/user_defined_views.html).\n* **Branching** - Create git-like [branches](https://bframe.work/features/branching.html) to test isolated changes using production data and then compare the results to the main branch\n* **Edits and amendments** - Easily make [edits](https://bframe.work/features/edits.html) or [amendments](https://bframe.work/features/amendments.html) to pricing and packaging.\n* **Time travel** - Rewind the [system time](https://bframe.work/features/system_time.html) of the business model to audit, debug and reconcile historical changes.\n\n## Installation\nOpen a terminal and run (Requires Python 3.9+):\n\n```bash\npip install bframelib\n```\n\n## Usage\n`bframelib` is a client that sits on top of a duckdb connection. Within the client is an interpreter that injects SQL based on the specified bframe views that are referenced (e.g. ``bframe.invoices``). [Additional options](https://bframe.work/interface_api/variables.html) are set within the library config and can control branching, system time and more.\n\nBelow is a short example to show the most direct usage of `bframelib`.\n\n```python\nfrom bframelib import Client\nconfig = {\n    \"org_id\": 1,\n    \"env_id\": 1,\n    \"branch_id\": 1,\n    \"rating_range\": ['2025-01-01', '2026-01-01']\n}\n\n# The client will create a duckdb connection if it is not provided\nbf = Client(config)\n\n# Set up your source data (bframe uses duckdb if a source is not specified)\nbf.execute(\"\"\"\n    -- Set up the tenant\n    INSERT INTO src.organizations (id, name) values (1, 'Your business');\n    INSERT INTO src.environments (id, org_id, name) values (1, 1, 'PROD');\n    INSERT INTO src.branches (id, org_id, env_id, name) values (1, 1, 1, 'main');\n\n    -- Create customer\n    INSERT INTO src.customers (org_id, env_id, branch_id, id, durable_id, name) values (1, 1, 1, 1, 'abc', 'Customer name');\n\n    -- Create product\n    INSERT INTO src.products (org_id, env_id, branch_id, id, name, ptype) values (1, 1, 1, 1, 'Item', 'FIXED');\n\n    -- Create contract and prices\n    INSERT INTO src.contracts (org_id, env_id, branch_id,  id, durable_id, customer_id, started_at, ended_at, effective_at) values (1, 1, 1, 1, 'abc_contract', 'abc', '2025-01-01', '2026-01-01', '2025-01-01');\n    INSERT INTO src.contract_prices (org_id, env_id, branch_id, id, product_uid, contract_uid, price, invoice_delivery, invoice_schedule) values (1, 1, 1, 1, 1, 1, '10.00', 'ARREARS', 1);\n\"\"\")\n\n# Generate invoices\nres = bf.execute(\"\"\"\n    SELECT \n        contract_id,\n        invoice_delivery,\n        started_at,\n        ended_at,\n        status,\n        total\n    FROM bframe.invoices\n    ORDER BY ended_at\n\"\"\")\n\nprint(res.fetch_df().to_string())\n#      contract_id invoice_delivery started_at   ended_at status  total\n# 0   abc_contract          ARREARS 2025-01-01 2025-02-01  DRAFT   10.0\n# 1   abc_contract          ARREARS 2025-02-01 2025-03-01  DRAFT   10.0\n# 2   abc_contract          ARREARS 2025-03-01 2025-04-01  DRAFT   10.0\n# 3   abc_contract          ARREARS 2025-04-01 2025-05-01  DRAFT   10.0\n# 4   abc_contract          ARREARS 2025-05-01 2025-06-01  DRAFT   10.0\n# 5   abc_contract          ARREARS 2025-06-01 2025-07-01  DRAFT   10.0\n# 6   abc_contract          ARREARS 2025-07-01 2025-08-01  DRAFT   10.0\n# 7   abc_contract          ARREARS 2025-08-01 2025-09-01  DRAFT   10.0\n# 8   abc_contract          ARREARS 2025-09-01 2025-10-01  DRAFT   10.0\n# 9   abc_contract          ARREARS 2025-10-01 2025-11-01  DRAFT   10.0\n# 10  abc_contract          ARREARS 2025-11-01 2025-12-01  DRAFT   10.0\n# 11  abc_contract          ARREARS 2025-12-01 2026-01-01  DRAFT   10.0\n    \n```\n\n## API\nThe `bframelib` is composed of a `Client` and `Interpreter`. The `Client` is the primary interface for library users and the `Interpreter` is the engine that powers the business logic. Both are exposed through the library but only more advanced use cases will utilize the interpreter directly.\n\n### `Source`\nA named tuple that represents a source.\n\n#### `__init__(src_type, connect_sql, init_schema)`\nThe initialization of the named tuple.\n\n**Parameters:**\n* `src_type` - An enum string to represent the source that is being attach. Possible values include ('core', 'branch', 'events').\n* `connect_sql` - A SQL string that is executed to assign the specified source. The function expects an `ATTACH` statement using the [duckdb SQL dialect](https://duckdb.org/docs/sql/statements/attach.html). An example of what this could look like: `\"ATTACH ':memory:' AS src;\"`\n* `init_schema` - A boolean with a default value of `False`. If set to `True` the source database attached will have the bframe schema executed on it.\n\n### `Client`\nA class that represents the bframe library interface for a duckdb connection.\n\n#### `config`\nA property to view the current configuration options.\n\n**Returns:**\nA dictionary of the library configurations that have been set.\n\n#### `__init__(config, sources, con)`\nThe initialization of the `Client` class.\n\n**Parameters:**\n* `config` - A dictionary containing configuration options. Detailed option definitions can be found [here](https://bframe.work/interface_api/variables.html).\n* `sources` - A list of `Source` tuples to be set. If no list is passed a default core source will be passed.\n* `con` - A pre-initialized [`duckdb connection`](https://duckdb.org/docs/api/python/reference/#duckdb.DuckDBPyConnection). If this is not present a new connection will be created.\n\n#### `set_config(config_updates)`\nA function to set configuration options.\n\n**Parameters:**\n* `config_updates` - A dictionary containing one or more updates to the library config. Detailed option definitions can be found [here](https://bframe.work/interface_api/variables.html).\n\n**Returns:**\nVoid\n\n#### `execute(query)`\nA function to interpret bframe SQL and execute it on the given duckdb connection.\n\n**Parameters:**\n* `query` - A string containing one or more SQL statements.\n\n**Returns:**\nA [`DuckDBPyConnection`](https://duckdb.org/docs/api/python/reference/#duckdb.DuckDBPyConnection) that holds the results of the executed SQL statement.\n\n#### `get_price_span_date_range(product_types)`\nA function to pull the maximum time range of the currently configured invoices. This can enable effective use of event source partitions (e.g. only sourcing events that are needed for invoice generation).\n\n**Parameters:**\n* `product_types` - A tuple that contains one or more product types\n\n**Returns:**\nA tuple with the first element representing the minimum start date of all invoices and the second element representing maximum end date of all invoices.\n\n#### `set_source(Source)`\nA function to set the `src` database bframe pulls data from. It will detach the existing `src` during execution.\n\n**Parameters:**\n* `connect_sql` - A SQL string that is executed to assign the `src` database. The function expects an `ATTACH` statement using the [duckdb SQL dialect](https://duckdb.org/docs/sql/statements/attach.html). An example of what this could look like: `\"ATTACH ':memory:' AS src;\"`\n* `init_schema` - A boolean with a default value of `False`. If set to `True` the `src` database attached will have the bframe schema executed on it.\n\n**Returns:**\nVoid\n\n#### `interpreter.add_table_template(name, template)`\nA function on the stored `Interpreter` class that sets a [user defined view](https://bframe.work/features/user_defined_view.html).\n\n**Parameters:**\n* `name` - A string that represents the view name (e.g. `bframe.YOUR_NAME_HERE`)\n* `template` - SQL that represents the view itself\n\n**Returns:**\nVoid\n\n## Resources\n\n[Documentation](https://bframe.work)\n\n[Github repository](https://github.com/bframe-work/bframelib)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbframe-work%2Fbframelib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbframe-work%2Fbframelib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbframe-work%2Fbframelib/lists"}