Unofficial Go SDK for calculating tax estimations using the Swiss federal tax calculator.
Warning
This repository was created by manually reverse engineering the REST API used by the official calculator. Its functionality can break at any time - not recommended for production use cases.
Supported tax types:
- Income & wealth tax
- Pension payout tax (retirement savings)
- Inheritance & gift tax
- Profit & capital taxes (for companies)
see the Examples on how to calculate them.
The current REST API of the tax calculator doesn't feature any (visible) rate limits or other access limitations - it is open for anyone to use. Please use this SDK responsibly in order for the API to stay this way.
go get -u github.com/ruegerj/swiss-tax-apiSee godoc reference for detailed API documentation.
Tip
Allthough the SDK ships with the (current) default base url of the calculator API as constant, it is recommended to use your own (configurable) value in order to react to changes more easily.
The examples showcase the builder api, which facilitates the construction of the rather complex request objects. However the request structs are exported by the package so that one could create by hand (if desired).
Note
For a better understanding of the parameters and terminology use the official reference (german only) or the UI of the calculator directly.
The tax calulation is city based in switzerland. Therefore you first must source the propriatery city-id of the location you want to calculate a tax for.
// zip code, name or fragments allowed as search term
req, _ := swisstaxapi.NewSearchCityRequest("Bern").
WithTaxYear(2024).
WithLanguage(swisstaxapi.LANGUAGE_DE).
Build()
client := swisstaxapi.NewClient(swisstaxapi.DEFAULT_BASE_URL)
result, _ := client.SearchCities(req)
cityId := result[0].TaxLocationId // value to be used for calc requestsTax calculation for normal citizens of switzerland.
req, _ := swisstaxapi.NewCalculateIncomeTaxRequestBuilder().
WithTaxYear(2025).
WithTaxLocation(600000000). // Lucerne
WithAge(25).
WithChildren(1, 2).
WithConfession(swisstaxapi.CONFESSION_ROMAN_CATHOLIC).
WithGrossIncome(200_000).
WithFortune(500_000).
WithRelationship(swisstaxapi.RELATIONSHIP_MARRIED).
// Partner* attributes only required for: mariages & civil partnerships
WithPartnerConfession(swisstaxapi.CONFESSION_CHRISTIAN_CATHOLIC).
WithPartnerAge(26).
WithPartnerNetIncome(100_000).
Build()
client := swisstaxapi.NewClient(swisstaxapi.DEFAULT_BASE_URL)
result, _ := client.CalculateIncomeAndWealthTax(req)
fmt.Println("church tax", result.ChurchTax())
fmt.Println("city tax", result.CityTax())
fmt.Println("canton tax", result.CantonalTax())
fmt.Println("federal tax", result.FederalTax())
fmt.Println("total income tax", result.TotalIncomeTax())
fmt.Println("total fortune tax", result.TotalFortuneTax())
fmt.Println("total tax", result.TotalTax)aka "Lump-sum payment from occupational retirement savings"
Tax calculation for when you want to pay out your retirement savings (e.g. for buying a house).
req, _ := swisstaxapi.NewCalculatePensionPayoutRequest().
WithTaxYear(2025).
WithTaxLocation(600000000). // Lucerne
WithRelationship(swisstaxapi.RELATIONSHIP_SINGLE).
WithConfession(swisstaxapi.CONFESSION_PROTESTANT).
WithGender(swisstaxapi.GENDER_MALE).
WithAgeAtPayment(65).
WithCapital(100_000).
Build()
client := swisstaxapi.NewClient(swisstaxapi.DEFAULT_BASE_URL)
result, _ := client.CalculatePensionPayoutTax(req)
fmt.Println("church tax", result.ChurchTax)
fmt.Println("city tax", result.CityTax)
fmt.Println("canton tax", result.CantonTax)
fmt.Println("federal tax", result.FederalTax)
fmt.Println("total tax", result.TotalTax())Tax when you are gifted something make an inheritance.
req, _ := swisstaxapi.NewCalculateGiftTaxRequest().
WithTaxYear(2025).
WithTaxLocation(600000000). // Lucerne
WithInheritance(100_000). // .WithGift(...) for gifts
Build()
client := swisstaxapi.NewClient(swisstaxapi.DEFAULT_BASE_URL)
result, _ := client.CalculateGiftTax(req)
// result has to be fetched for a conrecte relative kin
fianceResult := result.For(swisstaxapi.RELATIVE_KIND_FIANCE)
fmt.Println("fiance tax", staffTax.TaxTotal, staffTax.Deduction)Tax calculation for companies.
req, _ := swisstaxapi.NewCalculateProfitTaxRequest().
WithTaxYear(2025).
WithTaxLoaction(600000000). // Lucerne
WithProfitCalculationBeforeTax().
WithFederalTaxProfit(9_800_000).
WithCantonalTaxProfit(10_200_000).
WithTaxableCapital(65_000_000).
WithPaidUpCapital(5_000_000).
WithFederalNetRevenueOnParticipations(2_300_000).
WithCantonalNetRevenueOnParticipations(2_300_000).
WithPatentBoxReduction(1_500_000).
WithResearchAndDevelopmentDeduction(2_200_000).
WithSelfFinancingDeduction(800_000).
WithTotalAssets(110_000_000).
WithTotalShares(35_000_000).
Build()
client := swisstaxapi.NewClient(swisstaxapi.DEFAULT_BASE_URL)
result, _ := client.CalculateProfitTax(req)
fmt.Println("profit tax", result.ProfitTax())
fmt.Println("capital tax", result.CapitalTax())
fmt.Println("total tax", result.TotalTax())